2016-11-12 422 views
0

我想通過以下代碼合併幾個單獨的數據集。但是,它報告錯誤爲: enter image description here 我怎麼能解決這個問題?SAS-多個數據集合並

%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

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

'order by 1'子句是否有用? – Quentin

+1

它按照原始代碼中的成員名稱排序值。如果您使用'memname命令',則SAS會寫入一條筆記,表明您正在按列排序而不在結果集中。 – Tom

+0

俏皮。我想我通常只是忽略那個筆記。 – Quentin