[英]Executing PROC SOAP in a loop in SAS
Purpose of the code代码的目的
Code and Other information代码和其他信息
Below code creates three sample numbers that need to be used sequentially to make the webservice call.下面的代码创建了三个示例编号,需要依次使用这些编号来进行 Web 服务调用。
data cenis;
infile datalines;
input CENI 8.;
datalines;
13413745
12174391
8905899
;
The below code makes the webservice call for number (CENI) 13413745 and produces the output as shown in the snapshot.下面的代码使网络服务呼叫号码 (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;
Problem Statement问题陈述
I need all of this to work in a macro that can be put in a loop.我需要所有这些都在一个可以放入循环的宏中工作。 The final output should be three observations each corresponding to the respective number from the 'cenis' dataset.最终输出应该是三个观测值,每个观测值对应于“cenis”数据集中的相应数字。 My attempt to create the macro is as below我尝试创建宏如下
%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;
The above macro compiles correctly without any errors.上面的宏编译正确,没有任何错误。 Then when I try to execute the same for a specific number manually like below it creates errors.然后,当我尝试像下面这样手动对特定数字执行相同的操作时,它会产生错误。
%parse_single(13413745);
run;
The log is日志是
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
My first roadblock is to get the macro working correctly and the second roadblock is to make the %do loop work correctly.我的第一个障碍是让宏正常工作,第二个障碍是使 %do 循环正常工作。 When attempted the loop I am getting the same CARDS error.尝试循环时,我收到相同的卡片错误。
You cannot use CARDS/DATALINES in macro code.您不能在宏代码中使用卡片/数据线。 So do it some other way.所以用其他方式来做。
I would store the template in a file and use PROC STREAM to read the file and replace any macro expressions.我会将模板存储在一个文件中,并使用 PROC STREAM 读取文件并替换任何宏表达式。
Or just pass the values to your data _null_
as string literals.或者只是将值作为字符串文字传递给您的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;
Here is what worked.这是有效的。 All credits to my lovely wife!所有的功劳都归功于我可爱的妻子!
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.