繁体   English   中英

在 SAS 中循环执行 PROC SOAP

[英]Executing PROC SOAP in a loop in SAS

代码的目的

  1. 从 SAS 数据集中读取数字列表
  2. 通过将每个数字替换为 XML 信封中的变量来进行 Web 服务调用
  3. 将 XML 响应存储到临时/中间文件
  4. 解析上述文件以检索基本信息(即员工姓名和编号)并创建/附加数据集,该数据集最终为 #1 中的每个数字提供相关的员工信息。

代码和其他信息

下面的代码创建了三个示例编号,需要依次使用这些编号来进行 Web 服务调用。

data cenis;
 infile datalines; 
input CENI 8.;
datalines;
13413745
12174391
8905899
;

下面的代码使网络服务呼叫号码 (CENI) 13413745 并产生如快照所示的输出。

filename request temp;
filename response "/mktg/prc203/abhee/output.txt";

data _null_;
   file request;
   input;
   put _infile_;
   datalines4;

<soapenv:Envelope xmlns:sch="http://www.XXXX.com/XXXXservice/schema"
                  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:ndf="http://slsexxxdevt1.ute.XXXX.com:10149/XXXX/XXXXservice.wsdl">

<soapenv:Header/>
     <soapenv:Body>
           <sch:OwnerOnlyInquiryRequest>
           <sch:RequestHeader>
           <sch:ClientSystem>ePRS</sch:ClientSystem>
           </sch:RequestHeader>
           <sch:RequestParameterList>
           <sch:RequestParam>13413745</sch:RequestParam>
           </sch:RequestParameterList>
           <sch:RequestType>CESEID</sch:RequestType>
           <sch:PeckingOrder>Pricing</sch:PeckingOrder>
           <sch:ViewType>Pricing</sch:ViewType>
           </sch:OwnerOnlyInquiryRequest>
     </soapenv:Body>
</soapenv:Envelope>
;;;; 


proc soap in=request
          out=response
          url="http://slsexxxdevt1.ute.XXXX.com:10149/XXXX/XXXXservice.wsdl"
          soapaction="";
run;  

data output_dataset;
infile response dsd dlm = ' /';
input @"firstName=" firstName :$32. @"lastName=" lastName :$32. @"emplnbr=" emplnbr :8.;
run;

proc print data=output_dataset;
run;

上面代码的输出

问题陈述

我需要所有这些都在一个可以放入循环的宏中工作。 最终输出应该是三个观测值,每个观测值对应于“cenis”数据集中的相应数字。 我尝试创建宏如下

%macro parse_single(ID_VAR);
filename request temp;
filename response "/mktg/prc203/abhee/output.txt";

data _null_;
   file request;
   input;
   put _infile_;
   datalines4;

<soapenv:Envelope xmlns:sch="http://www.xxxx.com/xxxxservice/schema"
                  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:ndf="http://slsxxxxdevt1.ute.xxxx.com:10149/xxx/xxxxservice.wsdl">

<soapenv:Header/>
     <soapenv:Body>
           <sch:OwnerOnlyInquiryRequest>
           <sch:RequestHeader>
           <sch:ClientSystem>ePRS</sch:ClientSystem>
           </sch:RequestHeader>
           <sch:RequestParameterList>
           <sch:RequestParam>&ID_VAR</sch:RequestParam>
           </sch:RequestParameterList>
           <sch:RequestType>CESEID</sch:RequestType>
           <sch:PeckingOrder>Pricing</sch:PeckingOrder>
           <sch:ViewType>Pricing</sch:ViewType>
           </sch:OwnerOnlyInquiryRequest>
     </soapenv:Body>
</soapenv:Envelope>
;;;; 


proc soap in=request
          out=response
          url="http://slsxxxxdevt1.ute.xxxx.com:10149/xxxx/xxxxservice.wsdl"
          soapaction="";
run;  

data want;
infile response dsd dlm = ' /';
input @"Employee" @"firstName=" firstName :$32. @"lastName=" lastName :$32. @"emplnbr=" emplnbr :8.;
run;

proc print data=want;
run;

%mend parse_single;

上面的宏编译正确,没有任何错误。 然后,当我尝试像下面这样手动对特定数字执行相同的操作时,它会产生错误。

%parse_single(13413745);
run;

日志是

1                                                          The SAS System                          12:47 Wednesday, February 7, 2018

1          %_eg_hidenotesandsource;
5          %_eg_hidenotesandsource;
28         
29         %parse_single(13413745);

NOTE: The file REQUEST is:
      Filename=/var/xxxx/SAS/WORK/tmp/9.4/SAS_work75F400002FE8_mktpricing/#LN00038,
      Owner Name=e0836441,Group Name=pricing,
      Access Permission=-rw-r--r--,
      Last Modified=07Feb2018:14:56:06

ERROR: The macro PARSE_SINGLE generated CARDS (data lines) for the DATA step, which could cause incorrect results.  The DATA step 
       and the macro will stop executing.
NOTE: 0 records were written to the file REQUEST.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds

180: 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 180-322: Statement is not valid or it is used out of proper order.

ERROR: The macro PARSE_SINGLE will stop executing.
30         run;

31         
32         
33         %_eg_hidenotesandsource;
45         
46         
47         %_eg_hidenotesandsource;
50       

我的第一个障碍是让宏正常工作,第二个障碍是使 %do 循环正常工作。 尝试循环时,我收到相同的卡片错误。

您不能在宏代码中使用卡片/数据线。 所以用其他方式来做。

我会将模板存储在一个文件中,并使用 PROC STREAM 读取文件并替换任何宏表达式。

或者只是将值作为字符串文字传递给您的data _null_

data _null_;
   file request;
   put 
 '<soapenv:Envelope xmlns:sch="http://www.xxxx.com/xxxxservice/schema"'
/'                  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"'
/'             xmlns:ndf="http://slsxxxxdevt1.ute.xxxx.com:10149/xxx/xxxxservice.wsdl">'
/'<soapenv:Header/>'
/'     <soapenv:Body>'
/'           <sch:OwnerOnlyInquiryRequest>'
/'           <sch:RequestHeader>'
....
   ;
run;

这是有效的。 所有的功劳都归功于我可爱的妻子!

filename response "/mktg/prc203/abhee/output.txt";
data cenis;
infile datalines; 
input CENI $;
datalines;
13413745
12174391
8905899
;

%macro abc;
proc sql noprint;
 select count(*) into :cnt
 from CENIS;
quit;

%do x=1 %to &cnt;

filename outfile "/mktg/prc203/abhee/input.txt";

data _null_;
set cenis(firstobs=&x obs=&x);
file outfile;
string1='<soapenv:Envelope xmlns:sch="http://www.xxxxx.com/xxxxxservice/schema"';
string2='xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"';
string3='xmlns:ndf="http://slsxxxxxdevt1.ute.xxxxx.com:10149/xxxxx/xxxxxservice.wsdl">';
string4=compress('<sch:RequestParam>'||CENI||'</sch:RequestParam>');
put string1;
put @25 string2;
put @25 string3;
put '<soapenv:Header/>' /
@10 '<soapenv:Body>' /
@15 '<sch:OwnerOnlyInquiryRequest>' /
@15 '<sch:RequestHeader>' /
@15 '<sch:ClientSystem>ePRS</sch:ClientSystem>' /
@15 '</sch:RequestHeader>' /
@15 '<sch:RequestParameterList>' /
@15 string4 /
@15 '</sch:RequestParameterList>' /
@15 '<sch:RequestType>CESEID</sch:RequestType>' /
@15 '<sch:PeckingOrder>Pricing</sch:PeckingOrder>' /
@15 '<sch:ViewType>Pricing</sch:ViewType>' /
@15 '</sch:OwnerOnlyInquiryRequest>' /
@10 '</soapenv:Body>' /
'</soapenv:Envelope>'
;

run;

proc soap in=outfile
          out=response
          url="http://slsxxxxxdevt1.ute.xxxxx.com:10149/xxxxx/xxxxxservice.wsdl"
          soapaction="";
run;  
data want;
infile response dsd dlm = ' /';
input @"Employee" @"firstName=" firstName :$32. @"lastName=" lastName :$32. @"emplnbr=" emplnbr :8.;
run;

proc append base=FINAL data=want;
run;

%end;
%mend;

%abc;

proc print data=final;
run;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM