<?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 %to %end? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-to-end/m-p/522939#M142025</link>
    <description>&lt;P&gt;Hello:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following macro codes from the previous programmer who has been gone and no way to find.&amp;nbsp;&amp;nbsp; Could someone let me know what the 'fmt&amp;amp;i._' refer to and the 'Z' is refer to something?&amp;nbsp; Also,&amp;nbsp;does the 'Program' in the macro mean it need to run by using the 'data'&amp;nbsp;before the do loop?&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro in(program,z,data);

Libname Workshop "\\Pathway\data";


%include "\\Pathway\&amp;amp;program..sas";

data workshop.&amp;amp;data;
        length LABEL $ 200;
	set %do i=1 %to &amp;amp;z;
	fmt&amp;amp;i._ %end;;
	by FMTNAME START END LABEL;
run;

%mend in;

%in(ABC_Time_check,19,Time_formats);  
%in(ABC_Place_check,113,Place_formats);  
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Dec 2018 19:28:28 GMT</pubDate>
    <dc:creator>ybz12003</dc:creator>
    <dc:date>2018-12-20T19:28:28Z</dc:date>
    <item>
      <title>%do %to %end?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-to-end/m-p/522939#M142025</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following macro codes from the previous programmer who has been gone and no way to find.&amp;nbsp;&amp;nbsp; Could someone let me know what the 'fmt&amp;amp;i._' refer to and the 'Z' is refer to something?&amp;nbsp; Also,&amp;nbsp;does the 'Program' in the macro mean it need to run by using the 'data'&amp;nbsp;before the do loop?&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro in(program,z,data);

Libname Workshop "\\Pathway\data";


%include "\\Pathway\&amp;amp;program..sas";

data workshop.&amp;amp;data;
        length LABEL $ 200;
	set %do i=1 %to &amp;amp;z;
	fmt&amp;amp;i._ %end;;
	by FMTNAME START END LABEL;
run;

%mend in;

%in(ABC_Time_check,19,Time_formats);  
%in(ABC_Place_check,113,Place_formats);  
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 19:28:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-to-end/m-p/522939#M142025</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2018-12-20T19:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: %do %to %end?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-to-end/m-p/522943#M142026</link>
      <description>&lt;P&gt;When you execute the macro for the first time using&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token macroname"&gt;%in&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;ABC_Time_check&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;19&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;Time_formats&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/LI-CODE&gt;
&lt;P&gt;z would resolve to 19 as that is 2nd value in the positional parameter&amp;nbsp; in the defining %macro statement&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;program&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;z&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;Now, let's move on to find out what %do loop resolves to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run this and see the log&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro t;
%put set;
%do i=1 %to 19;/*z will resolve to 19*/
%put 	fmt&amp;amp;i._ ;
%end; 
%put %str(;);
%mend t;
%t
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;/*You will notice that loop generating list of dataset names fmt1_&amp;nbsp; to fmt19_&lt;/P&gt;
&lt;P&gt;set&amp;nbsp;&lt;BR /&gt;fmt1_&lt;BR /&gt;fmt2_&lt;BR /&gt;fmt3_&lt;BR /&gt;fmt4_&lt;BR /&gt;fmt5_&lt;BR /&gt;fmt6_&lt;BR /&gt;fmt7_&lt;BR /&gt;fmt8_&lt;BR /&gt;fmt9_&lt;BR /&gt;fmt10_&lt;BR /&gt;fmt11_&lt;BR /&gt;fmt12_&lt;BR /&gt;fmt13_&lt;BR /&gt;fmt14_&lt;BR /&gt;fmt15_&lt;BR /&gt;fmt16_&lt;BR /&gt;fmt17_&lt;BR /&gt;fmt18_&lt;BR /&gt;fmt19_&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;I am sure you know set keyword followed by datsets list is a concatenation/append operation&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 19:41:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-to-end/m-p/522943#M142026</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-20T19:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: %do %to %end?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-to-end/m-p/522947#M142027</link>
      <description>&lt;P&gt;if you compiled the macro, then this line&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%in(ABC_Place_check,113,Place_formats);  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;would call the macro, substituting values of&amp;nbsp; program=ABC_Place_check , z =113 , data=Place_formats&lt;/P&gt;&lt;P&gt;1) define the Workshop Libname&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Libname Workshop "\\Pathway\data";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;2) run the sas program \\Pathway\ABC_Place_check.sas&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include "\\Pathway\&amp;amp;program..sas";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;3)&amp;nbsp;append the datasets FMT1_ , FMT2_, .... , FMT113_ together and save to a dataset called PLACE_FORMATS in the workshop libname.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data workshop.&amp;amp;data;
        length LABEL $ 200;
	set %do i=1 %to &amp;amp;z;
	fmt&amp;amp;i._ %end;;
	by FMTNAME START END LABEL;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Try running the statement;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen mlogic mprint;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;before you run existing macro code, then look in the log . It should help you understand what is going on .&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 19:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-to-end/m-p/522947#M142027</guid>
      <dc:creator>34reqrwe</dc:creator>
      <dc:date>2018-12-20T19:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: %do %to %end?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-to-end/m-p/522948#M142028</link>
      <description>&lt;P&gt;You have a macro call "in" and it requires 3 parameters program, z &amp;amp; data&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following line calls the macro in and passes the values into the macro variables:&lt;/P&gt;
&lt;P&gt;program="ABC_Time_check"&lt;/P&gt;
&lt;P&gt;z="19"&lt;/P&gt;
&lt;P&gt;data="Time_formats"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token macroname"&gt;%in&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;ABC_Time_check&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;19&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;Time_formats&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;CODE&gt;&lt;/CODE&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically where you see any &amp;amp;&amp;lt;variable name&amp;gt; in the macro, the&amp;nbsp;&lt;SPAN&gt;&amp;amp;&amp;lt;variable name&amp;gt; is replaced with the value of the macro variable thus:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;program&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;z&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="token statement"&gt;Libname&lt;/SPAN&gt; Workshop &lt;SPAN class="token string"&gt;"\\Pathway\data"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="token macrostatement"&gt;%include&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;"\\Pathway\&lt;FONT color="#FF0000"&gt;ABC_Time_check&lt;/FONT&gt;.sas"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; workshop&lt;SPAN class="token punctuation"&gt;.&lt;FONT color="#FF0000"&gt;Time_formats&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="token function"&gt; length&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;LABEL&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;200&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="token keyword"&gt; set&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt; i&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%to&lt;/SPAN&gt; &lt;FONT color="#FF0000"&gt;19 &lt;/FONT&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; fmt&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;_ &lt;SPAN class="token macrostatement"&gt;%end&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="token statement"&gt; by&lt;/SPAN&gt; FMTNAME START END &lt;SPAN class="token function"&gt;LABEL&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="token macrobound"&gt;%mend&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;SPAN class="token macroname"&gt;%in&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;ABC_Time_check&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;19&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;Time_formats&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;&lt;SPAN class="token macroname"&gt;%in&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;ABC_Place_check&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;113&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;Place_formats&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;CODE&gt;&lt;/CODE&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The %do loop is going to iterate for the values 1&amp;nbsp;to 19 and resolve to generate the following set statement&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set fmt1_ fmt2_ fmt3_ ... fmt19_ ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro is the equivalent of the following code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Libname Workshop "\\Pathway\data";


%include "\\Pathway\ABC_Time_check.sas";

data workshop.Time_formats;
        length LABEL $ 200;
	set fmt1_ fmt2_ fmt3_ ... fmt_19 ;
	by FMTNAME START END LABEL;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 20:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-to-end/m-p/522948#M142028</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2018-12-20T20:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: %do %to %end?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-to-end/m-p/522949#M142029</link>
      <description>&lt;P&gt;Apparently the objective of code is to create SAS User Defined formats from Raw Data .&lt;BR /&gt;&lt;BR /&gt;For More Information on creating the User Defined formats based on the SAS Datasets refer to:&lt;BR /&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#n1e19y6lrektafn1kj6nbvhus59w.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#n1e19y6lrektafn1kj6nbvhus59w.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Could someone let me know what the 'fmt&amp;amp;i._' "&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;i is the counter that increments from 1 to 19 . For example when the first macro is called

%in(ABC_Time_check,19,Time_formats); 

fmt&amp;amp;i._ resolves to :

fmt1_
fmt2_
fmt3_
..
..
fmt19_


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;"refer to and the 'Z' is refer to something?&amp;nbsp; "&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Z is the 2rd parameter to the macro, This is positional

%macro in(program,z,data);

which resolve to 19, because it is in the second place of the macro call.
%in(ABC_Time_check,19,Time_formats); .&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;"Also, does the 'Program' in the macro mean it need to run by using the 'data' before the do loop?"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;every time you invoke themacro , You code is executing an external sas code before executing the data step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Refer to \\Pathway\ABC_Time_check.sas and \\Pathway\ABC_Place_check.sas&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps these sas codes create the datasets fmt1_ ..fmt19_ Etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to display the contents of the External code in the current log use the following global option.&lt;/P&gt;&lt;PRE&gt;options source2;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Dec 2018 20:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-to-end/m-p/522949#M142029</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2018-12-20T20:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: %do %to %end?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-to-end/m-p/523328#M142180</link>
      <description>&lt;P&gt;Note that SAS allows ranges of dataset names when the suffix is a number.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So IF you changed the names of your datasets so that the number was at the end.&amp;nbsp; So FMT_1 instead of FMT1_&amp;nbsp; then you could remove the %DO loop and just use :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set fmt_1 - fmt_&amp;amp;z ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you cannot change the names but you know that you want all of the datasets that start with FMT then perhaps you could use this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set FMT:  ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Dec 2018 15:34:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-to-end/m-p/523328#M142180</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-23T15:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: %do %to %end?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-to-end/m-p/527062#M143634</link>
      <description>&lt;P&gt;Thank you so much for all of elucidation.&amp;nbsp; &lt;img id="womanhappy" class="emoticon emoticon-womanhappy" src="https://communities.sas.com/i/smilies/16x16_woman-happy.png" alt="Woman Happy" title="Woman Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jan 2019 19:48:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-to-end/m-p/527062#M143634</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-01-14T19:48:06Z</dc:date>
    </item>
  </channel>
</rss>

