<?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 loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/790876#M253242</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_all;
%let date = %sysfunc(inputn(20220107,yymmdd8.));
%do %while (&amp;amp;date. le %sysfunc(inputn(20220128,yymmdd8.)));
  %let folder = %sysfunc(putn(&amp;amp;date.,yymmddn8.));

  data ds&amp;amp;folder.;
  infile "/path/&amp;amp;folder./data.txt" /* other options */
  input /* list of variables */;
  run;

  %let date = %eval(&amp;amp;date.+7);
%end;
%mend;
%import_all&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 19 Jan 2022 12:51:09 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-01-19T12:51:09Z</dc:date>
    <item>
      <title>Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/790815#M253215</link>
      <description>&lt;P&gt;data friday;&lt;BR /&gt;target=today();&lt;BR /&gt;do n=1 to 5 while(date &amp;lt; NWKDOM(5, 6, month(target),year(target)));&lt;BR /&gt;date=NWKDOM(n, 6, month(target),year(target));&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;format target date date9.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the above code, i got the output as:&lt;/P&gt;&lt;P&gt;07Jan2022&lt;/P&gt;&lt;P&gt;14Jan2022&lt;/P&gt;&lt;P&gt;21Jan2022&lt;/P&gt;&lt;P&gt;28Jan2022&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BUT,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro test;&lt;BR /&gt;%let target=today();&lt;BR /&gt;%do n=1 %to 5 while(date &amp;lt;NWKDOM(5, 6, month(target),year(target)));&lt;BR /&gt;%let date= NWKDOM(n,6, month(target),year(target));&lt;BR /&gt;output;&lt;BR /&gt;%end;&lt;BR /&gt;%mend test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When i run the above code with same condition, I got the output as:&lt;/P&gt;&lt;P&gt;07Jan2022&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output I want is:&lt;/P&gt;&lt;P&gt;07Jan2022&lt;/P&gt;&lt;P&gt;14Jan2022&lt;/P&gt;&lt;P&gt;21Jan2022&lt;/P&gt;&lt;P&gt;28Jan2022&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help me to overcome this situation!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want 4 macro values in a single macro variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TIA,&lt;/P&gt;&lt;P&gt;Joe&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 06:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/790815#M253215</guid>
      <dc:creator>Pooja98</dc:creator>
      <dc:date>2022-01-19T06:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/790816#M253216</link>
      <description>&lt;P&gt;Run your macro after issuing&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mlogic mprint symbolgen;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and post the log into a window opened with this button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;so we can point out the many issues.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 07:00:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/790816#M253216</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-19T07:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/790819#M253218</link>
      <description>&lt;P&gt;441 options mlogic mprint symbolgen;&lt;BR /&gt;442&lt;BR /&gt;443 %macro test;&lt;BR /&gt;444 %let target=today();&lt;BR /&gt;445 %do n=1 %to 5 while(date &amp;lt;NWKDOM(5, 6, month(target),year(target)));&lt;BR /&gt;446 %let date= NWKDOM(n,6, month(target),year(target));&lt;BR /&gt;447 output;&lt;BR /&gt;448 %end;&lt;BR /&gt;449 %mend test;&lt;BR /&gt;450&lt;BR /&gt;451 %put &amp;amp;date;&lt;BR /&gt;SYMBOLGEN: Macro variable DATE resolves to 07JAN2022&lt;BR /&gt;07JAN2022&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the log i got&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 07:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/790819#M253218</guid>
      <dc:creator>Pooja98</dc:creator>
      <dc:date>2022-01-19T07:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/790825#M253223</link>
      <description>&lt;P&gt;You never actually &lt;EM&gt;call&lt;/EM&gt; your macro, so the value displayed from the macro variable comes from and earlier code submit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But let's go to the macro code itself (I am now on my main desktop, not on my tablet):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
%let target=today(); /* to get the RESULT(!) of a function in macro language, you have to wrap it into the %SYSFUNC macro function */
%do n=1 %to 5 while(date &amp;lt;NWKDOM(5, 6, month(target),year(target)));
/* The keyword WHILE would have to be %WHILE to be recognized by the macro processor,
   but you cannot combine %TO with %WHILE in macro language */
/* You also must call macro variables by using ampersands, otherwise the macro variable names are only text */
/* And you also must wrap all function calls in %SYSFUNC */
%let date= NWKDOM(n,6, month(target),year(target));
/* Use ampersands and %SYSFUNC */
output; /* this would simply create a sequence of OUTPUT statements wherever the macro is called,
   the validity depends on where the macro is called */
%end;
%mend test;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your data step creates a dataset, which cannot be done from a macro (except with&amp;nbsp;&lt;STRONG&gt;VERY&lt;/STRONG&gt; advanced macro coding techniques, from which you are lightyears right now). What should the macro do?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 08:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/790825#M253223</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-19T08:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/790832#M253227</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have four folders (name: 20220107, 20220114, 20220121, 20220128) each folder contain some observation related to the folder date. Data's are in the text format. I want to import all weekly data into SAS when i run the import code only once.</description>
      <pubDate>Wed, 19 Jan 2022 09:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/790832#M253227</guid>
      <dc:creator>Pooja98</dc:creator>
      <dc:date>2022-01-19T09:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/790876#M253242</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_all;
%let date = %sysfunc(inputn(20220107,yymmdd8.));
%do %while (&amp;amp;date. le %sysfunc(inputn(20220128,yymmdd8.)));
  %let folder = %sysfunc(putn(&amp;amp;date.,yymmddn8.));

  data ds&amp;amp;folder.;
  infile "/path/&amp;amp;folder./data.txt" /* other options */
  input /* list of variables */;
  run;

  %let date = %eval(&amp;amp;date.+7);
%end;
%mend;
%import_all&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jan 2022 12:51:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/790876#M253242</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-19T12:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/790907#M253258</link>
      <description>&lt;P&gt;Create a program (not a macro) that reads the files from one of the folders.&lt;/P&gt;
&lt;P&gt;Perhaps your program looks something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile '/toplevel/20220107/alldata.txt' dsd firstobs=2 truncover;
  input id date :yymmdd. var1-var10;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now change the date part of the folder name to macro variable reference. Make sure to use double quotes instead of single quotes so the macro variable reference will work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datestr=20220107;
data want;
  infile "/toplevel/&amp;amp;datestr./alldata.txt" dsd firstobs=2 truncover;
  input id date :yymmdd. var1-var10;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you get that working now convert it to a macro that uses that macro variable as a parameter. And try calling it with the same date string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro readone(datestr);
data want;
  infile "/toplevel/&amp;amp;datestr./alldata.txt" dsd firstobs=2 truncover;
  input id date :yymmdd. var1-var10;
run;
%mend;
%readone(datestr=20220107)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use the dataset you have with the list of dates to call that macro once for each date.&lt;/P&gt;
&lt;P&gt;Say you had a dataset named FRIDAYS with a variable named DATE that had a SAS date (numeric variable with number of days since 1960).&amp;nbsp; Use PUT() to convert the date into the digit string your macro needs. Use CATS() to generate the macro call. Use CALL EXECUTE() to push the call onto the stack to run after the data step finishes.&amp;nbsp; Use the %NRSTR() macro function to delay running of the macro until the command is pull back off the stack to be executed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set fridays;
  call execute(cats('%nrstr(%readone)(datestr=',put(date,yymmddn8.),')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jan 2022 15:15:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/790907#M253258</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-19T15:15:45Z</dc:date>
    </item>
  </channel>
</rss>

