DATA Step, Macro, Functions and more

Macro Loop

Reply
Contributor
Posts: 31

Macro Loop

 

Hi SAS Users,

 

I am having multiple SAS datasets in the below mentioned paths.

 

libname base "C:/SASUniversityEdition/myfolders/sasuser.v94/base"; /*(e.g. have_base, adverse_base, conmeds_base)*/
libname current "C:/SASUniversityEdition/myfolders/sasuser.v94/current"; /*(e.g. have_current, adverse_current,conmeds_current)*/

 

now we want to pickup all SAS datasets from the corresponding path and run it on the code.

 

lile it has to pick up have_base data from /base path and have_current data from /current path then run the code and generate the output in one dataset. AND
it has to pick up adverse_base data from /base path and adverse_current data from /current path then run the code and generate the output in one dataset.
finally all output datasets should be one final dataset.

 

/*data in have_base*/
data have_base;
input name $ value month $;
cards;
bala 402 jun
sri 593 sep
sudh 543 jul
;
run;
proc sort data=have_ base;
by name;
run;

 

/*data in have_current*/

data have_current;
input name $ value month $;
cards;
bal 432 jun
sri 543 sep
sudh 563 jul
;
run;
proc sort data=have_current;
by name;
run;

 

data both;
merge have_base(in=a) have_current(in=b);
by name;
if a and b;
run;

 

please do let me know if am not clear.

 

Kind Regards,
Raju

Super User
Posts: 19,782

Re: Macro Loop

Please post working code that accomplishes what you want to turn into a macro.  

 

Then identify the places that will be dynamic - ie change the data set names.

 

 

Contributor
Posts: 31

Re: Macro Loop

data both;
merge have_base(in=a) have_current(in=b);
by name;
if a and b;
run;

 

this is the working code.

 

now have_base and have_current datasets has to take from the paths which I have mentioned. then it has to check for other datasets (adverse_base and adverse_current) and so on....

Super User
Posts: 11,343

Re: Macro Loop

Do you mean that have_base, adverse_base, conmeds_base,have_current, adverse_current,conmeds_current all end up in the same data set?

 

Contributor
Posts: 31

Re: Macro Loop

not exactly.

 

we have to pick datasets from the mentioned paths and it has to pass through the following code (first it should check for have_base and base_current then adverse_base and adverse_current and so on.... then finally all outputs should be in one dataset or if we have multiple outputs that is also fine).

 

data both;
merge have_base(in=a) have_current(in=b);
by name;
if a and b;
run;

Ask a Question
Discussion stats
  • 4 replies
  • 271 views
  • 1 like
  • 3 in conversation