BookmarkSubscribeRSS Feed
saipriya92
Calcite | Level 5

Hi, I want to create a SAS macro that will be used to create dataset names for each dataset. 

 

 

 

 

I made it earlier but don't remember it. It was something like this: 

 

%macro test ( dataset1= , dataset 2= );

%mend;

 

% test;

 

Data &dataset1. ;

Set abc;

Run;

 

Data &dataset2.;

Set xtz;

Run;

 

%mend test;

 

%test;

%dataset1=data_1:

%dataset2= data_2;

%mend test;

 

Is the above code correct??

 

2 REPLIES 2
Criptic
Lapis Lazuli | Level 10

Hey @saipriya92 ,

 

so this coding will not even run, but I guess that is why you are here.

 

The question is what do you want? Create dataset names for each dataset? What rules should the naming convention follow, etc.?

 

Please post an example of your input and your expected output.

 

Kind Regards

Criptic

Kurt_Bremser
Super User

Writing a macro

%macro mymac(ds1=,ds2=);
data &ds1.;
set &ds2.;
run;
%mend;

so that you can use

%mymac(ds1=abc,ds2=xyz)

just to automate

data abc;
set xyz;
run;

is only a waste of time. And it makes programs less maintainable, because now everyone (and that includes your future YOU!) has to look for the macro code in another place, instead of seeing what will happen right there on the spot.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 834 views
  • 0 likes
  • 3 in conversation