BookmarkSubscribeRSS Feed
Raj_C
Obsidian | Level 7

 

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

4 REPLIES 4
Reeza
Super User

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.

 

 

Raj_C
Obsidian | Level 7

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....

ballardw
Super User

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

 

Raj_C
Obsidian | Level 7

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1789 views
  • 1 like
  • 3 in conversation