Solved

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

Posted on 2012-03-21
2
394 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now