BookmarkSubscribeRSS Feed
sourav22
Calcite | Level 5

Hi All,

My requirement here is to merge 'n' number of datasets in a library using a sas macro as that seems to be the feasible solution.The sas datasets' names in the library are all different i.e.,does not start with the same prefix. all the datasets have a common variable which is date and the datasets have to be merged based on date. The data in the datasets are already sorted. I tried using proc sql to first gather all the variables in a macro variable. From there on how should the merge be accomplished?

2 REPLIES 2
error_prone
Barite | Level 11

The requirement sounds like homework. You don't need the names of the variables to merge the datasets. You need the names of the datasets in the library - the dataset sashelp.vtable holds that information.

 

proc sql noprint;
  select catx(".", LibName, MemName)
    into :datasetList separated by " "
    from sashelp.vtable
      where LibName = "YOUR_LIB_IN_UPCASE"
  ;
quit;

data work.merged;
  merge &datasetList.;
  by Date;
run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I just want to add that in a real life situation you wouldn't do this mass merge.  It is fraught with unseen dangers, such as variables being in different tables, different types, many to many merges etc.  Normally you should know your data well, and be able to pick out data items only when needed.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1043 views
  • 2 likes
  • 3 in conversation