簡體   English   中英

使用SAS的宏合並數據集,但SAS無法識別目標名稱

[英]SAS-using macro combine dataset but SAS doesn't recognise the target name

我使用以下代碼將一個庫中的幾個數據集與一個數據集結合在一起。 但是,根據日志文件,SAS無法在宏中識別&target..*

日志文件如下所示: 在此處輸入圖片說明

%macro combintprice(sourcelib=,from=,going=,target=);
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:numb 
  from mytables;

  %let numb=&numb.;  /*give a number to datasets in the library*/

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

%do i=1 %to &numb.;

proc sql;
create table &going.&&memname&i. as
select &from.&&memname&i...*, &target..*
from &from.&&memname&i. as a left join &target. as b 
on a.date=b.date;
quit;
%end;
%mend;

%combintprice(sourcelib='AXP',from=AXP.,going=WORK.,target=axp1);

在調試這類東西時,通常有助於將代碼分解為幾部分。 讓我們嘗試使用一些虛擬輸入來運行它,並跳過第一個proc sql

%let memname1= data1;
%let memname2= data2;
%let memname3= data3;


%let numb = 3;


%macro combintprice(sourcelib=,from=,going=,target=);

%do i=1 %to &numb.;
proc sql noexec;
create table &going.&&memname&i. as
select &from.&&memname&i...*, &target..*
from &from.&&memname&i. as a left join &target. as b 
on a.date=b.date;
quit;
%end;
%mend;

%combintprice(sourcelib='AXP',from=AXP.,going=WORK.,target=axp1.);

這給出了以下日志輸出:

22: LINE and COLUMN cannot be determined.
 NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
 ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?, 
               AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN, LENGTH, 
               LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.  
 200: LINE and COLUMN cannot be determined.
 NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
 ERROR 200-322: The symbol is not recognized and will be ignored.
 NOTE 137-205: Line generated by the invoked macro "COMBINTPRICE".
 76           proc sql noexec; create table &going.&&memname&i. as select &from.&&memname&i...*, &target..* from &from.&&memname&i.
                                                                                                         _
                                                                                                         22
 76       ! as a left join &target. as b  on a.date=b.date; quit;
 ERROR 22-322: Syntax error, expecting one of the following: a name, *. 

因此,問題在於您的宏代碼生成了無效的SQL。 proc sql生成的所有那些錯誤消息(即使設置了noexec)和宏變量的位實際上都在這里受到影響,因此,讓我們使用等效的%put語句查看生成的實際代碼是什么樣的:

%let memname1= data1;
%let memname2= data2;
%let memname3= data3;


%let numb = 3;


%macro combintprice(sourcelib=,from=,going=,target=);

%do i=1 %to &numb.;
%put 
proc sql;
%put create table &going.&&memname&i. as
select &from.&&memname&i...*, &target..*
from &from.&&memname&i. as a left join &target. as b 
on a.date=b.date;
%put quit;
%end;
%mend;

%combintprice(sourcelib='AXP',from=AXP.,going=WORK.,target=axp1.);

這就是結果(僅省略了幾個分號):

 proc sql
 create table WORK.data1 as select AXP.data1.*, axp1..* from AXP.data1 as a left join axp1. as b  on a.date=b.date
 quit

您的期間過多。 嘗試解決此問題,以便僅生成有效的SQL,然后它可以按預期工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM