?
Solved

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

Posted on 2012-03-21
2
Medium Priority
?
417 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 2000 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

777 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