Solved

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

Posted on 2012-03-21
2
407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

749 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