Neal801
Neal801

Reputation: 307

SAS-multiple datasets merging

I want to merge several individual datasets through following code. However, it reports error as: enter image description here How could I solve this problem?

%macro test(sourcelib=,from=); 
proc sql noprint;  /*read datasets in a library*/
  create table mytables as
  select *
  from dictionary.tables
  where libname = &sourcelib
  order by memname ;

  select count(memname) 
  into:obs 
  from mytables;

  %let obs=&obs.;

  select memname
  into : memname1-:memname&obs.
  from mytables;
quit;


data full;
set
%do i=1 %to &obs.;
  &from.&&memname&i;
%end;
;
run;
%mend;

%test(sourcelib='RESULT',from=RESULT.);

Upvotes: 0

Views: 1163

Answers (1)

Tom
Tom

Reputation: 51566

Your %DO loop is generating extra semi-colons in the middle of your SET statement.

set
%do i=1 %to &obs.;
  &from.&&memname&i
%end;
;

Also why do you have two macro parameters to pass the same information? You should be able to just pass in the libref. Also why make so many macro variables when one will do?

%macro test(sourcelib=);
%local memlist ;
proc sql noprint;
  select catx('.',libname,memname) into :memlist separated by ' '
    from dictionary.tables
    where libname = %upcase("&sourcelib")
    order by 1
  ;
quit;

data full;
  set &memlist ;
run;
%mend;

%test(sourcelib=ReSulT);

Upvotes: 1

Related Questions