Hi everybody,
I want to loop on a PROC execution. Is it possible? I can do a loop inside a data step, but I cannot call a PROC inside a data step since -as far as I know
I want to call a PROC SOAP, which sometimes works and sometimes returns and empty file. I want to keep executing the PROC SOAP until the response has more than zero bytes.
I would like to do something like this:
data _null_;
filesize = 0;
do while (filesize = 0)
PROC SOAP in='c:\temp\request.xml' out='c:\temp\response.xml' url='http://some.web.service' soapaction='http://some.soap.action'; run;
rc = filename ('req', 'C:\temp\response.xml');
fid = fopen ('req');
infoname = foptname (fid, 4);
filesize = finfo(fid, infoname);
end;
run;
Do you know how to solve this?
Thanks a lot!!
The DOSUBL function might be another option. It can execute SAS code (e.g. a macro containing several DATA and PROC steps) from within a DATA step. However, in your case I'd prefer a macro solution as has been suggested.
You can't run a SAS procedure inside a DATA step. PROC SOAP will need to be moved prior to the DATA step, then most likely you will need to use macro code to do the looping. You could possibly do the file checking in macro as well but might be easier to stick with the DATA step if you are not familiar with the macro function %SYSFUNC.
Your best bet is probably to put the Proc call inside a macro with a %do %until construct. You can see an example of %do %until here http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543770.htm
Thanks Chris. I think I am almost there, but the code is not working. Should I use %sysfunc to call PROC SOAP? Is that possible?
/* not working */
%local rc fid fidc;
%local Bytes CreateDT ModifyDT;
%do %until(&Bytes > 0);
PROC SOAP
in=reqFile
out=respFile
url=&url
soapaction=&soapAction;
RUN;
%let rc=%sysfunc(filename(onefile,&webServicesResponseFile));
%let fid=%sysfunc(fopen(&onefile));
%let Bytes=%sysfunc(finfo(&fid,File Size (bytes)));
%let fidc=%sysfunc(fclose(&fid));
%let rc=%sysfunc(filename(onefile));
%put NOTE: File size of &filename is &Bytes bytes;
%end;
No, you only use %sysfunc with functions, not procedures.
Without seeing the log it's difficult to know exactly where your problem lies. If you still want to try this method could you post a copy of your log.
The DOSUBL function might be another option. It can execute SAS code (e.g. a macro containing several DATA and PROC steps) from within a DATA step. However, in your case I'd prefer a macro solution as has been suggested.
Thanks Reinhard! It looks like this is working.
This is the code snippet
DATA _null_;
responseFileSize = 0;
do while (responseFileSize = 0);
rc = DOSUBL("PROC SOAP in=reqFile out=respFile url=&url soapaction=&soapAction");
fid=fopen('respFile');
infoname = foptname(fid, 4);
responseFileSize = finfo(fid,infoname);
fid = fclose('respFile');
end;
run;
@HGimenez: Great that DOSUBL works for you (really without a semicolon after the PROC SOAP statement?). Honestly, I'm not familiar with PROC SOAP. When I quickly tested my suggestion last night I used PROC EXPORT (creating a dummy file response.xml) instead, but for some reason my SAS session didn't like it and crashed. Therefore, I didn't recommend DOSUBL wholeheartedly (without further testing). But I used DOSUBL repeatedly and successfully in a big project where it called a macro containing DATA and PROC steps. So, I knew that it should work in principle.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.