DATA Step, Macro, Functions and more

Merge all datasets in library

Accepted Solution Solved
Reply
Contributor
Posts: 62
Accepted Solution

Merge all datasets in library

I have 15 datasets in a library. the data is already sorted. is there a way to merge them all together with out having to write each one out?

Thanks!


Accepted Solutions
Solution
‎04-27-2012 01:08 PM
Super Contributor
Posts: 1,636

Re: Merge all datasets in library

data class1 class2 class3;
  set sashelp.class;
  run;

/*  if your datasets begin with same letters */
  data want;
   merge c:;
   by name;
  run;

/* begin with different letters */

proc sql noprint;
   select memname into : names
     from dictionary.tables
    where libname='WORK'; /* note: libname must be in upcase */
data want;
   merge &names;
   by name;
  run;

View solution in original post


All Replies
Solution
‎04-27-2012 01:08 PM
Super Contributor
Posts: 1,636

Re: Merge all datasets in library

data class1 class2 class3;
  set sashelp.class;
  run;

/*  if your datasets begin with same letters */
  data want;
   merge c:;
   by name;
  run;

/* begin with different letters */

proc sql noprint;
   select memname into : names
     from dictionary.tables
    where libname='WORK'; /* note: libname must be in upcase */
data want;
   merge &names;
   by name;
  run;

Contributor
Posts: 62

Re: Merge all datasets in library

Thanks Lin Lin!

this is just what i was looking for.

Smiley Happy

Contributor
Posts: 62

Re: Merge all datasets in library

the SQL method seems to merge class1 only.

Super Contributor
Posts: 1,636

Re: Merge all datasets in library

sorry. using the updated one:

proc sql noprint;

   select memname into : names separated by '  '

     from dictionary.tables

       where libname='WORK'; /* note: libname must be in upcase */

data want;

   merge &names;

   by name;

  run;

Linlin

Valued Guide
Posts: 765

Re: Merge all datasets in library

hi ... just modify the code (without "SEPARATED BY" you only get one memname)  ...

proc sql noprint;

select memname into : names separated by ' '

from dictionary.tables

where libname='WORK'; /* note: libname must be in upcase */

quit;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 3721 views
  • 1 like
  • 3 in conversation