SAS多重数据集合并

时间:2016-11-12 18:37:20

标签: loops macros sas

我想通过以下代码合并几个单独的数据集。但是,它报告错误为: enter image description here 我怎么能解决这个问题?

%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.);

1 个答案:

答案 0 :(得分:1)

您的%DO循环在SET语句中间生成了额外的分号。

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

为什么你有两个宏参数来传递相同的信息?你应该能够传入libref。还有为什么要做这么多的宏变量?

%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);