BookmarkSubscribeRSS Feed
harigottala0
Fluorite | Level 6

Dear All,

I am fetch the data through API. for this I am using the proc soap. So, I am send the request file and getting the response file and storing in a particular location. My issue is I need to check that file created based on the size of file and if not i need to run the proc soap still file is created with data.

 

%macro ac(A=);

%do %until (%EVAL(&fid +0)> 0);
/* Sending the request to API and getting the response from API using PROC SOAP */
proc soap
IN=&w.req
OUT=&w.resp
URL="xxxxxxx"
SOAPACTION="xxxxxxx"
WEBUSERNAME="xxxx"
WEBPASSWORD="xxxxxx";
run;

%LET outall=&inpath.&dc._&w._Response1.xml;
/* To check if the File is exist or not in particular location */
/* To check file Empty or Non-empty based on the size of the file to further process */
%let filrf=myfile;

%if %sysfunc(fileexist(&outall)) %then
%do;
%let rc=%sysfunc(filename(filrf,&outall));
%let fid=%sysfunc(fopen(&filrf));
%put &fid.;
%if &fid > 0 %then
%do;
%let rc=%sysfunc(fread(&fid));
%let rc=%sysfunc(fget(&fid,mystring));

%if &rc = 0 %then
%do;
%put File is Non-Empty;
%end;
%else %put File is Empty: Error: I/O Read timed out;
%let rc=%sysfunc(fclose(&fid));
%end;

%let rc=%sysfunc(filename(filrf));
%end;
%else %put file does not exist;
%end;
%mend ac;
%ac(A=1);

5 REPLIES 5
AlexBennasar
Obsidian | Level 7

Some more information will be fine...is your code working, or what's the issue with it?

also, if the file is an xml, you can import it directly to a SAS dataset, by defining a map that defines it's structure (or the part you want to import) and a libname. Once imported, you can check whatever you need. I give you a real example of one of my projects:

filename rssmap temp;
data _null_;
 infile datalines;
 file rssmap;
 input;
 put _infile_;
 datalines;
<?xml version="1.0" encoding="UTF-8"?>
<SXLEMAP name="RSSMAP" version="2.1">
  <NAMESPACES count="0"/>
  <TABLE name="item">
    <TABLE-PATH syntax="XPath">/sr:codelists/sr:codelist</TABLE-PATH>
    <COLUMN name="resourceID">
      <PATH syntax="XPath">/sr:codelists/sr:codelist/cdomain:id</PATH>
      <TYPE>character</TYPE>
      <DATATYPE>string</DATATYPE>
      <LENGTH>800</LENGTH>
    </COLUMN>
    <COLUMN name="urn">
      <PATH syntax="XPath">/sr:codelists/sr:codelist/cdomain:urn</PATH>
      <TYPE>character</TYPE>
      <DATATYPE>string</DATATYPE>
      <LENGTH>5000</LENGTH>
    </COLUMN>
   </TABLE>
</SXLEMAP>
;
run;

libname myxml xmlv2 xmlfileref=yourfile xmlmap=rssmap compat=yes;

data codelist;
  set myxml.item;
run;

Hope this helps

 

 

 

harigottala0
Fluorite | Level 6

Hi Alex,

 

My code is working fine. I will give some more information on my issue. 

Issue : When ever we are send the request to get the response using proc soap, somtime,  I am getting  I/O error or Read out time .... So, as per my code, once this error is coming , it will comeout of loop and once again i need to submit the code. But i don't want in this way...It should once again go and access the API untill the response file is created.

AlexBennasar
Obsidian | Level 7

So a

%do %while(&rc ne 0)

will do the job, won't it?

harigottala0
Fluorite | Level 6

Hi Alex,

 

It is not working.

 

Thanks,

 

 

 

harigottala0
Fluorite | Level 6

Hi,

 

Step1: Creating the request file.

Step2: Sending the request file to fetch the response file.

proc soap

IN=&w.req

OUT=&w.resp

URL="xxxxxxx"

SOAPACTION="xxxxxxx"

WEBUSERNAME="xxxx"

WEBPASSWORD="xxxxxx";

run;

 

Step3: Sometime it is creating the non-empty response file (with data), sometimes it is creating the empty response file due to I/O error or Read out time.

harigottala0_0-1657348152834.png

 

So, as per my code it is coming out of loop and going for next iteration. But I don’t to come out of loop

and go to next iteration unless it create a non-empty response file. If it is empty response file it should go to step2

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 846 views
  • 0 likes
  • 2 in conversation