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
Solved

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

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

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…

809 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