<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Download correct xml in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Download-correct-xml/m-p/803869#M316550</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;This is very helpful. I tried to include add this to my existing code, but unfortunately, I wasn't able to do it properly and get anything out of it. Here's the code I'm using. I've a list of urls in my file (named 'url') from which I need xmls (each url generates one xml). Destinations are named as 'file'. Each xml are saved in an unique name in the same folder. Both columns (url and file) are in data set test1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;filename code temp;
data _null_;
  set test1;
  file code;
  put  '
    filename out ' file :$quote. ';'
     /  ' proc http method="get"'
     /  ' url='  url :$quote.
     /  ' out=out'
     /  '; run;'
  ;
run;

%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 24 Mar 2022 18:59:47 GMT</pubDate>
    <dc:creator>92568466</dc:creator>
    <dc:date>2022-03-24T18:59:47Z</dc:date>
    <item>
      <title>Download correct xml</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Download-correct-xml/m-p/803612#M316444</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm using the following program to download xmls from a list of urls that I've stored in a dataset called test. 'file' is the destination (a folder name with unique file name), and 'url' is the address to xmls that I intend to download.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;filename code temp;&lt;BR /&gt;data _null_;&lt;BR /&gt;set test;&lt;BR /&gt;file code;&lt;BR /&gt;put '&lt;BR /&gt;filename out ' file :$quote. ';'&lt;BR /&gt;/ ' proc http method="get"'&lt;BR /&gt;/ ' url=' url :$quote.&lt;BR /&gt;/ ' out=out'&lt;BR /&gt;/ '; run;'&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%include code / source2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code works great. However, I download all xmls, if valid or not. As an example, url A below is a valid xml, whereas url B is an invalid xml. I'm wondering if I can condition to download only the valid ones, and not download the invalid ones (like url B). I'm just concerned as I might need to download about a million files, and unnecessary/invalid ones make further data process cumbersome.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://s3.amazonaws.com/irs-form-990/201313169349300441_public.xml" target="_blank"&gt;A: https://s3.amazonaws.com/irs-form-990/201313169349300441_public.xml&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://s3.amazonaws.com/irs-form-990/201103159349302715_public.xml" target="_blank"&gt;B: https://s3.amazonaws.com/irs-form-990/201103159349302715_public.xml&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 17:36:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Download-correct-xml/m-p/803612#M316444</guid>
      <dc:creator>92568466</dc:creator>
      <dc:date>2022-03-23T17:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: Download correct xml</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Download-correct-xml/m-p/803670#M316452</link>
      <description>&lt;P&gt;If you cannot figure out if PROC HTTP sets some status flag you could always just check the beginning of the file.&lt;/P&gt;
&lt;P&gt;For example this code will create a macro variable named STATUS with a value or either 0 or 1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let status=0;
data _null_;
  infile out ;
  input;
  if _infile_^=:'&amp;lt;Error' then call symputx('status','1');
  stop;
run;  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Mar 2022 19:45:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Download-correct-xml/m-p/803670#M316452</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-23T19:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: Download correct xml</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Download-correct-xml/m-p/803722#M316471</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;I'm not sure where I should place your code. I tried wrapping it inside my code, and running after my code. Looks like it reads only the first file. Can you help?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 00:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Download-correct-xml/m-p/803722#M316471</guid>
      <dc:creator>92568466</dc:creator>
      <dc:date>2022-03-24T00:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: Download correct xml</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Download-correct-xml/m-p/803734#M316476</link>
      <description>&lt;P&gt;Figure out what code you want to run.&amp;nbsp; Then convert it to a macro that takes as input the URL and target filename. Then use the data step from the other answer to generate one macro call per observation in your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC HTTP does set macro variables.&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0mwmz1upde0tqn1ptt5rnlly0tc.htm" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p0mwmz1upde0tqn1ptt5rnlly0tc.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the basic structure of your macro might be something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro getxml(url,file);
filename out &amp;amp;file ;
proc http method='get' out=out url=&amp;amp;url;
run;
%if&amp;nbsp;"&amp;amp;SYS_PROCHTTP_STATUS_PHRASE" ne "OK" %then %do;
  %put ERROR: Unable to retrieve &amp;amp;=url.;
  %put ERROR: &amp;amp;=SYS_PROCHTTP_STATUS_PHRASE;
  %put NOTE: Removing &amp;amp;=file.  %sysfunc(fdelete(out));
%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 04:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Download-correct-xml/m-p/803734#M316476</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-24T04:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: Download correct xml</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Download-correct-xml/m-p/803869#M316550</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;This is very helpful. I tried to include add this to my existing code, but unfortunately, I wasn't able to do it properly and get anything out of it. Here's the code I'm using. I've a list of urls in my file (named 'url') from which I need xmls (each url generates one xml). Destinations are named as 'file'. Each xml are saved in an unique name in the same folder. Both columns (url and file) are in data set test1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;filename code temp;
data _null_;
  set test1;
  file code;
  put  '
    filename out ' file :$quote. ';'
     /  ' proc http method="get"'
     /  ' url='  url :$quote.
     /  ' out=out'
     /  '; run;'
  ;
run;

%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 18:59:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Download-correct-xml/m-p/803869#M316550</guid>
      <dc:creator>92568466</dc:creator>
      <dc:date>2022-03-24T18:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: Download correct xml</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Download-correct-xml/m-p/803870#M316551</link>
      <description>&lt;P&gt;Once you get the macro to work you can then use a similar process to generate the macro calls instead of generating the code it is generating now.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  set test1;
  file code;
  put  '%getxml('  url= :$quote. ',' file= :$quote. ')';&lt;BR /&gt;run;

%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Mar 2022 19:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Download-correct-xml/m-p/803870#M316551</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-24T19:07:37Z</dc:date>
    </item>
  </channel>
</rss>

