<?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: %DO and %IF Statements Macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DO-and-IF-Statements-Macros/m-p/542960#M150070</link>
    <description>&lt;P&gt;Also note that proc append would be more efficient than recreating the data set 100 times.&lt;/P&gt;</description>
    <pubDate>Wed, 13 Mar 2019 22:28:01 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2019-03-13T22:28:01Z</dc:date>
    <item>
      <title>%DO and %IF Statements Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-and-IF-Statements-Macros/m-p/542948#M150067</link>
      <description>&lt;P&gt;I need help with a macro for reading in and combining zip files. There are 100 zip files that I need to read into SAS and combine into one dataset. The filenames are of the form: file-00000data.csv.gz, file-00001data.csv.gz,..., file-00099data.csv.gz&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The way I have written my macro, Files 00000-00009 need to be handled separately from Files 00010-00099, but I don't now how to create the two cases within the macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the first 10 files, the following macro works:&lt;/P&gt;&lt;P&gt;data combined_data;&lt;BR /&gt;set _null_; **empty dataset to add your data to one file at a time;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro unzip_data(filenum);&lt;BR /&gt;%do i=0 %to &amp;amp;filenum;&lt;BR /&gt;filename fromzip zip "&amp;amp;wallet.file-0000&amp;amp;i.data.csv.gz" GZIP;&lt;BR /&gt;data newdata;&lt;BR /&gt;infile fromzip delimiter = ',' MISSOVER DSD firstobs=2 ;&lt;BR /&gt;informat id best32. bucket_1 best32. bucket_2 best32.;&lt;BR /&gt;format id best12. bucket_1 best12. bucket_2 best12.;&lt;BR /&gt;input id bucket_1 bucket_2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data combined_data;&lt;BR /&gt;set combined_data newdata;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend unzip_data;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I am having trouble creating the code for handling all of the files (the below code is not working):&lt;/P&gt;&lt;P&gt;%macro unzip_data(filenum);&lt;BR /&gt;%do i=0 %to &amp;amp;filenum;&lt;BR /&gt;%if i&amp;lt;10 %then %do;&lt;BR /&gt;filename fromzip zip "&amp;amp;wallet.file-0000&amp;amp;i.data.csv.gz" GZIP;&lt;BR /&gt;data newdata;&lt;BR /&gt;infile fromzip delimiter = ',' MISSOVER DSD firstobs=2 ;&lt;BR /&gt;informat id best32. bucket_1 best32. bucket_2 best32.;&lt;BR /&gt;format id best12. bucket_1 best12. bucket_2 best12.;&lt;BR /&gt;input id bucket_1 bucket_2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data combined_data;&lt;BR /&gt;set combined_data newdata;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%else %do;&lt;BR /&gt;filename fromzip zip "&amp;amp;wallet.file-000&amp;amp;i.data.csv.gz" GZIP;&lt;BR /&gt;data newdata;&lt;BR /&gt;infile fromzip delimiter = ',' MISSOVER DSD firstobs=2 ;&lt;BR /&gt;informat id best32. bucket_1 best32. bucket_2 best32.;&lt;BR /&gt;format id best12. bucket_1 best12. bucket_2 best12.;&lt;BR /&gt;input id bucket_1 bucket_2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data combined_data;&lt;BR /&gt;set combined_data newdata;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend unzip_data;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 21:32:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-and-IF-Statements-Macros/m-p/542948#M150067</guid>
      <dc:creator>kadag68</dc:creator>
      <dc:date>2019-03-13T21:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: %DO and %IF Statements Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-and-IF-Statements-Macros/m-p/542959#M150069</link>
      <description>&lt;P&gt;Create a variable&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let fileno=%sysfunc(putn(&amp;amp;i,z4.));&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 22:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-and-IF-Statements-Macros/m-p/542959#M150069</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-03-13T22:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: %DO and %IF Statements Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-and-IF-Statements-Macros/m-p/542960#M150070</link>
      <description>&lt;P&gt;Also note that proc append would be more efficient than recreating the data set 100 times.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 22:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-and-IF-Statements-Macros/m-p/542960#M150070</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-03-13T22:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: %DO and %IF Statements Macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-and-IF-Statements-Macros/m-p/542961#M150071</link>
      <description>&lt;P&gt;ChrisNZ gave a better solution for what you are trying to do, but FYI you were missing an &amp;amp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;%if i&amp;lt;10 %then %do;
/*should be*/
%if &amp;amp;i&amp;lt;10 %then %do;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 22:34:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-and-IF-Statements-Macros/m-p/542961#M150071</guid>
      <dc:creator>34reqrwe</dc:creator>
      <dc:date>2019-03-13T22:34:51Z</dc:date>
    </item>
  </channel>
</rss>

