Solved

Creating a macro in SAS to read a dataset and match one field to get another

Posted on 2012-03-21
2
402 Views
Last Modified: 2012-03-22
I would like to code a SAS program that simply reads a dataset and matches Field_A to A_Field on the other dataset.

The complexity comes in that I would like to be able to read different files that may have different names for Field_A.

Is there a way to do this so that same program can be used for different files>
0
Comment
Question by:morinia
  • 2
2 Comments
 
LVL 14

Accepted Solution

by:
Aloysius Low earned 500 total points
ID: 37751332
i would suggest using call execute function to dynamically generate the required sas code on the fly:

data _null_;
  set [input with Field_A];
  call execute("proc sql;");
  call execute("  create table [output] as");
  call execute("    select * ");
  call execute("    from [input with A_Field]");
  call execute("    where [input with A_Field].A_Field = '" || trim(left(Field_A)) || "';");
  call execute("quit;");
run;
0
 
LVL 14

Assisted Solution

by:Aloysius Low
Aloysius Low earned 500 total points
ID: 37751344
the above solution is useful if there are multiple records in the dataset for Field_A.

if there's only 1 record, you could do:
data _null_;
  set [input with Field_A];
  call symput("Field_A", Field_A);
run;

proc sql;
  create table [output] as
    select *
    from [input with A_Field]
    where [input with A_Field].A_Field = "&Field_A";
quit;
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question