<?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 Do while and do until alternatives to loop through a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-while-and-do-until-alternatives-to-loop-through-a-dataset/m-p/598178#M172470</link>
    <description>&lt;P&gt;&lt;FONT color="#3366FF"&gt;Neither the do While or Do Until loop are working as to be expected.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;First example is Do While, there are four records in data set "ds" that meet the criteria,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;The dsname variable of the first record is passed to the macro, which unzips the data set with&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;an extension of ".gz",&amp;nbsp; Otherwise the dataset is not touched,&amp;nbsp; Loop terminates after one record in unpacked.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;For this dataset - which is just a&amp;nbsp; list of file names in the folder -&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;&amp;nbsp;/data/dev/share/test -&amp;nbsp; four records&amp;nbsp;meet the criteria.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;The variable "ddname" correctly resolves to dsname, which is simply the name of the .gz dataset.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;Code to create data set of file names in directory:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;%let path='/data/dev/share/test';&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;filename parent "&amp;amp;path";&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;data files;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;length fullfilename $90;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;length dsname $34;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;length ext $3;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;/*declaring ext(tension) var, but not populating, same with dsname */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;drop rc did i;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;did=dopen("parent");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;if did &amp;gt; 0 then do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;do i=1 to dnum(did);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;fullfilename=dread(did,i);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;output;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;rc=dclose(did);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;else put 'Could not open directory';&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;data ds;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;set files;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;/*now populate ext var, dsname */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;ext=substr(fullfilename,length(fullfilename)-2,3);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;dsname=substr(fullfilename,1,index(fullfilename, '.')-1);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do while Loop (doesn't work):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;DATA _null_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;length ddname $67.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;DATA _null_; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;set ds; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;do while (ext = ".gz");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;call symput('ddName', dsName);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%Macro1(data/dev/share/test,&amp;amp;ddname /data//dev/share/tmp);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;END;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;The Do Until does no better:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;DATA _null_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;length ddname $67.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;DO UNTIL (EOF);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;SET ds END=EOF;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;WHERE ext = ".gz";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;call symput('ddName', dsName);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%Macro1(/data/dev/share/test,&amp;amp;ddname,/data/dev/share/tmp);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;END;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;Again, the variable "ddName" correctly resolves to the name of the first record of a .gz&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;data set, no more records are processed after the first data set is unpacked.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;I need the loops to continue until all the records are processed that meet the&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;criteria ext = "gz", not just one.&amp;nbsp; There may be several hundred data sets in the folder, &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;a couple hundred&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;sas7bdat, a couple hundred sas7bdat.gz&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;What alternatives are there for looping through a data set and then acting (passing variable dsname to&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;a macro that unpacks the compressed datasets to a temporary folder)?:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 21 Oct 2019 17:17:53 GMT</pubDate>
    <dc:creator>Jumboshrimps</dc:creator>
    <dc:date>2019-10-21T17:17:53Z</dc:date>
    <item>
      <title>Do while and do until alternatives to loop through a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-while-and-do-until-alternatives-to-loop-through-a-dataset/m-p/598178#M172470</link>
      <description>&lt;P&gt;&lt;FONT color="#3366FF"&gt;Neither the do While or Do Until loop are working as to be expected.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;First example is Do While, there are four records in data set "ds" that meet the criteria,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;The dsname variable of the first record is passed to the macro, which unzips the data set with&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;an extension of ".gz",&amp;nbsp; Otherwise the dataset is not touched,&amp;nbsp; Loop terminates after one record in unpacked.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;For this dataset - which is just a&amp;nbsp; list of file names in the folder -&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;&amp;nbsp;/data/dev/share/test -&amp;nbsp; four records&amp;nbsp;meet the criteria.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;The variable "ddname" correctly resolves to dsname, which is simply the name of the .gz dataset.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;Code to create data set of file names in directory:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;%let path='/data/dev/share/test';&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;filename parent "&amp;amp;path";&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;data files;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;length fullfilename $90;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;length dsname $34;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;length ext $3;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;/*declaring ext(tension) var, but not populating, same with dsname */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;drop rc did i;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;did=dopen("parent");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;if did &amp;gt; 0 then do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;do i=1 to dnum(did);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;fullfilename=dread(did,i);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;output;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;rc=dclose(did);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;else put 'Could not open directory';&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;data ds;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;set files;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;/*now populate ext var, dsname */&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;ext=substr(fullfilename,length(fullfilename)-2,3);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;dsname=substr(fullfilename,1,index(fullfilename, '.')-1);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do while Loop (doesn't work):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;DATA _null_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;length ddname $67.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;DATA _null_; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;set ds; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;do while (ext = ".gz");&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;call symput('ddName', dsName);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;%Macro1(data/dev/share/test,&amp;amp;ddname /data//dev/share/tmp);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;END;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;The Do Until does no better:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;DATA _null_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;length ddname $67.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;DO UNTIL (EOF);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;SET ds END=EOF;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;WHERE ext = ".gz";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;call symput('ddName', dsName);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;%Macro1(/data/dev/share/test,&amp;amp;ddname,/data/dev/share/tmp);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;END;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;Again, the variable "ddName" correctly resolves to the name of the first record of a .gz&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;data set, no more records are processed after the first data set is unpacked.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;I need the loops to continue until all the records are processed that meet the&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;criteria ext = "gz", not just one.&amp;nbsp; There may be several hundred data sets in the folder, &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;a couple hundred&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;sas7bdat, a couple hundred sas7bdat.gz&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;What alternatives are there for looping through a data set and then acting (passing variable dsname to&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#3366FF"&gt;a macro that unpacks the compressed datasets to a temporary folder)?:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2019 17:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-while-and-do-until-alternatives-to-loop-through-a-dataset/m-p/598178#M172470</guid>
      <dc:creator>Jumboshrimps</dc:creator>
      <dc:date>2019-10-21T17:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: Do while and do until alternatives to loop through a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-while-and-do-until-alternatives-to-loop-through-a-dataset/m-p/598187#M172474</link>
      <description>&lt;P&gt;Why do you have a call to a macro in the middle of a data step? Does the macro only generate part of a data step?&lt;/P&gt;
&lt;P&gt;Can you show the macro you are trying to call?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2019 17:37:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-while-and-do-until-alternatives-to-loop-through-a-dataset/m-p/598187#M172474</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-21T17:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: Do while and do until alternatives to loop through a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-while-and-do-until-alternatives-to-loop-through-a-dataset/m-p/598198#M172483</link>
      <description>&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am going to guess that you expect the macro to be executed once for each record. It sounds like you expect that macro to read external data either with Proc Import or something else. The data step calling the Macro would stop in that case as you would have one of the "boundaries" such as a Proc or another Data statement that would end the first data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this &lt;STRONG&gt;may&lt;/STRONG&gt; get closer:&lt;/P&gt;
&lt;PRE&gt;DATA _null_; 
   set ds; 
   where ext = ".gz";
   length str $ 100;
   str = (cats,'%Macro1(data/dev/share/test,', dsname,'/data//dev/share/tmp)');
   call execute (str);
RUN;&lt;/PRE&gt;
&lt;P&gt;One reason I say "may" is that there are two quite different calls to your macro .&lt;/P&gt;
&lt;P&gt;With the above you might consider actually creating a data set and see if the values of the variable STR look like the macro calls you want to make if this doesn't quite work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is one place where you do not want to use double quotes in the function around %macro1. Use of single quotes should prevent it from attempting to execute during the data step. Call Execute stacks code to be executed after the data step completes.&lt;/P&gt;
&lt;P&gt;Or write the STR values out to a text file and use %include to execute the file for execution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2019 18:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-while-and-do-until-alternatives-to-loop-through-a-dataset/m-p/598198#M172483</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-21T18:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: Do while and do until alternatives to loop through a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-while-and-do-until-alternatives-to-loop-through-a-dataset/m-p/598200#M172485</link>
      <description>&lt;P&gt;What are you having trouble with exactly?&amp;nbsp; Is the first data step that appears to find file names work?&lt;/P&gt;
&lt;P&gt;If so then show an example of two or three of the values that it should generate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you just trying to use the data from that dataset to generate calls to your macro?&lt;/P&gt;
&lt;P&gt;Assuming you macro takes two inputs.&amp;nbsp; First the file name of the .gz file and second the member name of the dataset you want it to create then your program might look like this.&amp;nbsp; No DO loops needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set files;
  length ext $20 dsname $32 ;
  if index(fullfilename,'.') then ext=scan(fullfilename,-1,'.');
  if ext='gz';
  dsname = scan(fullfilename,-2,'./\');
  call execute(cats('%nrstr(%macro1)(',fullfilename,',',dsname,')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Oct 2019 18:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-while-and-do-until-alternatives-to-loop-through-a-dataset/m-p/598200#M172485</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-21T18:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: Do while and do until alternatives to loop through a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-while-and-do-until-alternatives-to-loop-through-a-dataset/m-p/598237#M172511</link>
      <description>I had to clean up the log extensively (below).&lt;BR /&gt;Macro is working, resolving ddname as the name of the dataset to be gunzipped, folders are hard coded an correctly resolved as ZIPFLPTH and UNZPFLPTH respectively. All loops I tried just stop at one record&lt;BR /&gt;Also using DO I=1 TO N; returns the same result: Bottom record is processed to the macro, all other records are not processed.&lt;BR /&gt;&lt;BR /&gt;1191 %c14_uzip_v3(/data/dev/share/test,&amp;amp;ddname,data/dev/share/tmp);&lt;BR /&gt;MLOGIC(C14_UZIP_V3): Beginning execution.&lt;BR /&gt;SYMBOLGEN: Macro variable DDNAME resolves to cmu&lt;BR /&gt;MLOGIC(C14_UZIP_V3): Parameter ZIPFLPTH has value /data/dev/share/test&lt;BR /&gt;MLOGIC(C14_UZIP_V3): Parameter ZPFLNAME has value cmu&lt;BR /&gt;MLOGIC(C14_UZIP_V3): Parameter UNZPFLPTH has value data/dev/share/tmp&lt;BR /&gt;MLOGIC(C14_UZIP_V3): %LET (variable name is FILREF)&lt;BR /&gt;SYMBOLGEN: Macro variable ZIPFLPTH resolves to /data/dev/share/test&lt;BR /&gt;SYMBOLGEN: Macro variable FILREF resolves to /data/dev/share/test&lt;BR /&gt;SYMBOLGEN: Macro variable ZPFLNAME resolves to cmu&lt;BR /&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;BR /&gt;SYMBOLGEN: Macro variable FILREF resolves to /data/dev/share/test&lt;BR /&gt;SYMBOLGEN: Macro variable ZPFLNAME resolves to cmu&lt;BR /&gt;MLOGIC(C14_UZIP_V3): %IF condition (%sysfunc(exist(&amp;amp;filref..&amp;amp;zpflname.)) = 0) &amp;amp;&amp;amp;&lt;BR /&gt;%sysfunc(fileexist("&amp;amp;filref./&amp;amp;zpflname..sas7bdat.gz")) is TRUE&lt;BR /&gt;MPRINT(C14_UZIP_V3): x filedef xdf clear;&lt;BR /&gt;SYMBOLGEN: Macro variable ZIPFLPTH resolves to /data/dev/share/test&lt;BR /&gt;SYMBOLGEN: Macro variable ZPFLNAME resolves to cmu&lt;BR /&gt;SYMBOLGEN: Macro variable UNZPFLPTH resolves to data/dev/share/tmp&lt;BR /&gt;SYMBOLGEN: Macro variable ZPFLNAME resolves to cmu&lt;BR /&gt;MPRINT(C14_UZIP_V3): x "gunzip -c /data/dev/share/test/cmu.sas7bdat.gz &amp;gt;&lt;BR /&gt;data/dev/share/tmp/cmu.sas7bdat";&lt;BR /&gt;SYMBOLGEN: Macro variable UNZPFLPTH resolves to data/dev/share/tmp&lt;BR /&gt;SYMBOLGEN: Macro variable ZPFLNAME resolves to cmu&lt;BR /&gt;MPRINT(C14_UZIP_V3): x "chmod 770 data/dev/share/tmp/cmu.sas7bdat";&lt;BR /&gt;SYMBOLGEN: Macro variable UNZPFLPTH resolves to data/dev/share/tmp&lt;BR /&gt;SYMBOLGEN: Macro variable ZPFLNAME resolves to cmu&lt;BR /&gt;MPRINT(C14_UZIP_V3): x "chgrp group1 data/dev/share/tmp/cmu.sas7bdat";&lt;BR /&gt;MLOGIC(C14_UZIP_V3): Ending execution.&lt;BR /&gt;1192 END;&lt;BR /&gt;1193 RUN;</description>
      <pubDate>Mon, 21 Oct 2019 19:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-while-and-do-until-alternatives-to-loop-through-a-dataset/m-p/598237#M172511</guid>
      <dc:creator>Jumboshrimps</dc:creator>
      <dc:date>2019-10-21T19:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Do while and do until alternatives to loop through a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-while-and-do-until-alternatives-to-loop-through-a-dataset/m-p/598246#M172516</link>
      <description>&lt;P&gt;Those SYMBOLGEN and MLOGIC lines are probably just making your log confusing.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So it looks like your macro generates some X commands.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1191 %c14_uzip_v3(/data/dev/share/test,&amp;amp;ddname,data/dev/share/tmp);
MPRINT(C14_UZIP_V3): x filedef xdf clear;
MPRINT(C14_UZIP_V3): x "gunzip -c /data/dev/share/test/cmu.sas7bdat.gz &amp;gt; data/dev/share/tmp/cmu.sas7bdat";
MPRINT(C14_UZIP_V3): x "chgrp group1 data/dev/share/tmp/cmu.sas7bdat";
&lt;/PRE&gt;
&lt;P&gt;Why are you trying to run those in the middle of a data step?&amp;nbsp; That doesn't make any sense.&amp;nbsp; You are essentially doing this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xxx;
  do i=1 to 5;
   x filedef xdf clear;
   x "gunzip -c /data/dev/share/test/cmu.sas7bdat.gz &amp;gt; data/dev/share/tmp/cmu.sas7bdat";
   x "chgrp group1 data/dev/share/tmp/cmu.sas7bdat";
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will just run the same three X commands 5 times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;NOTE the missing root node on the output directory name is also probably not helping.&amp;nbsp; data/... is a relative path, while /data/... is an absolute path.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead you probably want to take the value of some data step variable and use it to replace the reference to the macro variable DDNAME in the macro call and generate the macro calls to run after the data step finishes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if your input dataset is named HAVE and it has a variable named NAME with the value that corresponds to the value of &amp;amp;DDNAME then the code might look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xx;
  set have;
  call execute(cats
('%nrstr(%c14_uzip_v3)(/data/dev/share/test'&lt;BR /&gt;,',',NAME
,',','/data/dev/share/tmp)'
));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Although not sure you need the macro at all.&amp;nbsp; &amp;nbsp;Whatever logic you had in the macro (calls to the EXIST() and FILEEXIST() functions) could probably be done easier in a data step instead. You could then just generate the X commands directly using the data step.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2019 20:01:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-while-and-do-until-alternatives-to-loop-through-a-dataset/m-p/598246#M172516</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-21T20:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: Do while and do until alternatives to loop through a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-while-and-do-until-alternatives-to-loop-through-a-dataset/m-p/598252#M172520</link>
      <description>&lt;P&gt;If you can run X commands then why are you making getting the list of filenames so hard?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=/data/dev/share/test ;

data files ;
  infile "ls &amp;amp;path/*.sas7bdat.gz" pipe truncover ;
  input filename $256. ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Oct 2019 20:10:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-while-and-do-until-alternatives-to-loop-through-a-dataset/m-p/598252#M172520</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-21T20:10:45Z</dc:date>
    </item>
  </channel>
</rss>

