<?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/509917#M137157</link>
    <description>&lt;P&gt;You could CALL EXECUTE print them as you go.&amp;nbsp; It's a bit fiddly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;34   data _null_;
35      set sashelp.class end=last;
36      sname=name;
37      lname=trim(reverse(name));
38      length n $8;
39      n=put(_n_,8.-l);
40      call symputX('sname'||n,sname,'G');
41      call symputX('lname'||n,lname,'G');
42      call execute(cats('%put NOTE: &amp;amp;=sname',n,'- &amp;amp;=lname',n,';'));
43      if last then call symputX('count',_n_);
44      run;

NOTE: SNAME1=Alfred- LNAME1=derflA
NOTE: SNAME2=Alice- LNAME2=ecilA
NOTE: SNAME3=Barbara- LNAME3=arabraB
NOTE: SNAME4=Carol- LNAME4=loraC
NOTE: SNAME5=Henry- LNAME5=yrneH
NOTE: SNAME6=James- LNAME6=semaJ
NOTE: SNAME7=Jane- LNAME7=enaJ
NOTE: SNAME8=Janet- LNAME8=tenaJ
NOTE: SNAME9=Jeffrey- LNAME9=yerffeJ
NOTE: SNAME10=John- LNAME10=nhoJ
NOTE: SNAME11=Joyce- LNAME11=ecyoJ
NOTE: SNAME12=Judy- LNAME12=yduJ
NOTE: SNAME13=Louise- LNAME13=esiuoL
NOTE: SNAME14=Mary- LNAME14=yraM
NOTE: SNAME15=Philip- LNAME15=pilihP
NOTE: SNAME16=Robert- LNAME16=treboR
NOTE: SNAME17=Ronald- LNAME17=dlanoR
NOTE: SNAME18=Thomas- LNAME18=samohT
NOTE: SNAME19=William- LNAME19=mailliW
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

NOTE: There were 19 observations read from the data set SASHELP.CLASS.

NOTE: CALL EXECUTE routine executed successfully, but no SAS statements were generated.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 02 Nov 2018 15:30:41 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2018-11-02T15:30:41Z</dc:date>
    <item>
      <title>Do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/509904#M137146</link>
      <description>&lt;P&gt;Hi experts:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have Call Symput program shown below.&amp;nbsp;&amp;nbsp; My macro Count '_n_' is 781.&amp;nbsp;&amp;nbsp; I would like to&amp;nbsp;get&amp;nbsp;the 'sname' and 'lname' labeled&amp;nbsp;as below&amp;nbsp;&amp;nbsp;from 1st to the last (781).&amp;nbsp; Please advice how to approach this, maybe 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;data want;
			set test end=last;
			call symput('sname'||left(put(_n_,3.)),left(trim(Length)));
			call symput('lname'||left(put(_n_,3.)),left(trim(label)));
			if last then call symput('count',_n_);
run;

%put &amp;amp;sname1 &amp;amp;lname1 &amp;amp;sname781 &amp;amp;lname781 &amp;amp;count;

%macro ttt;
	 %do i=1 %to &amp;amp;count;
	 %put &amp;amp;i;
		label &amp;amp;&amp;amp;sname&amp;amp;i="&amp;amp;&amp;amp;lname&amp;amp;i";
	 %end;
%mend ttt;
%ttt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;The Log is&amp;nbsp;shown&amp;nbsp;error&amp;nbsp;message.&amp;nbsp;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;MLOGIC(TTT): %DO loop index variable I is now 781; loop will iterate again.&lt;/P&gt;
&lt;P&gt;MLOGIC(TTT): %PUT &amp;amp;i&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable I resolves to 781&lt;/P&gt;
&lt;P&gt;781&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable I resolves to 781&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable SNAME781 resolves to Culture4&lt;/P&gt;
&lt;P&gt;NOTE: Line generated by the invoked macro "TTT".&lt;/P&gt;
&lt;P&gt;1561 label &amp;amp;&amp;amp;sname&amp;amp;i="&amp;amp;&amp;amp;lname&amp;amp;i";&lt;/P&gt;
&lt;P&gt;-----&lt;/P&gt;
&lt;P&gt;180&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable I resolves to 781&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable LNAME781 resolves to CHART REVIEW 2 Culture4: Other&lt;/P&gt;
&lt;P&gt;culture&lt;/P&gt;
&lt;P&gt;MPRINT(TTT): label Culture4="CHART REVIEW 2 Culture4: Other culture&lt;/P&gt;
&lt;P&gt;result";&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 19:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/509904#M137146</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2018-11-02T19:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/509907#M137149</link>
      <description>&lt;P&gt;And what is not working with that?&amp;nbsp; I have tried it with data I have - noting that you have not provided any test data in the form of datastep requested many times before - and it works fine:&lt;/P&gt;
&lt;PRE&gt;data want;
   set sashelp.class end=last;
   call symput(cats('sname',put(_n_,3.)),strip(name));
   if last then call symput('count',_n_);
run;
%put &amp;amp;sname1 &amp;amp;sname2 &amp;amp;count;&lt;/PRE&gt;
&lt;P&gt;Do note, you can use cat functions to simplfy code, and strip() rather than trim(left()).&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 15:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/509907#M137149</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-02T15:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/509910#M137151</link>
      <description>&lt;P&gt;If you really want to print ALL of these macro variables, this is how to do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro print;
%do i=1 %to &amp;amp;count;
    %put &amp;amp;=i &amp;amp;&amp;amp;sname&amp;amp;i &amp;amp;&amp;amp;lname&amp;amp;i;
%end;
%mend;
%print&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But why go through that effort?&amp;nbsp;You can print these values from the SAS data set WANT via PROC PRINT.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 15:18:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/509910#M137151</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-02T15:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/509913#M137154</link>
      <description>&lt;P&gt;I don't want to print, I would like to get it via Data set.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 15:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/509913#M137154</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2018-11-02T15:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/509915#M137155</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I don't want to print, I would like to get it via Data set.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But its already in a data set. Why are you creating macro variables if you want something in a data set? I don't understand.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 15:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/509915#M137155</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-02T15:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/509917#M137157</link>
      <description>&lt;P&gt;You could CALL EXECUTE print them as you go.&amp;nbsp; It's a bit fiddly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;34   data _null_;
35      set sashelp.class end=last;
36      sname=name;
37      lname=trim(reverse(name));
38      length n $8;
39      n=put(_n_,8.-l);
40      call symputX('sname'||n,sname,'G');
41      call symputX('lname'||n,lname,'G');
42      call execute(cats('%put NOTE: &amp;amp;=sname',n,'- &amp;amp;=lname',n,';'));
43      if last then call symputX('count',_n_);
44      run;

NOTE: SNAME1=Alfred- LNAME1=derflA
NOTE: SNAME2=Alice- LNAME2=ecilA
NOTE: SNAME3=Barbara- LNAME3=arabraB
NOTE: SNAME4=Carol- LNAME4=loraC
NOTE: SNAME5=Henry- LNAME5=yrneH
NOTE: SNAME6=James- LNAME6=semaJ
NOTE: SNAME7=Jane- LNAME7=enaJ
NOTE: SNAME8=Janet- LNAME8=tenaJ
NOTE: SNAME9=Jeffrey- LNAME9=yerffeJ
NOTE: SNAME10=John- LNAME10=nhoJ
NOTE: SNAME11=Joyce- LNAME11=ecyoJ
NOTE: SNAME12=Judy- LNAME12=yduJ
NOTE: SNAME13=Louise- LNAME13=esiuoL
NOTE: SNAME14=Mary- LNAME14=yraM
NOTE: SNAME15=Philip- LNAME15=pilihP
NOTE: SNAME16=Robert- LNAME16=treboR
NOTE: SNAME17=Ronald- LNAME17=dlanoR
NOTE: SNAME18=Thomas- LNAME18=samohT
NOTE: SNAME19=William- LNAME19=mailliW
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

NOTE: There were 19 observations read from the data set SASHELP.CLASS.

NOTE: CALL EXECUTE routine executed successfully, but no SAS statements were generated.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Nov 2018 15:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/509917#M137157</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2018-11-02T15:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/510012#M137197</link>
      <description>&lt;P&gt;So, I created some codes followed the Call Symput codes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ttt;
	 %do i=1 %to &amp;amp;count;
	 %put &amp;amp;i;
		label &amp;amp;&amp;amp;sname&amp;amp;i="&amp;amp;&amp;amp;lname&amp;amp;i";
	 %end;
%mend ttt;

%ttt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I got an error message shown below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1561 label &amp;amp;&amp;amp;sname&amp;amp;i="&amp;amp;&amp;amp;lname&amp;amp;i";&lt;/P&gt;
&lt;P&gt;-----&lt;/P&gt;
&lt;P&gt;180&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is wrong with my codes?&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 18:53:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/510012#M137197</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2018-11-02T18:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/510014#M137199</link>
      <description>&lt;P&gt;This macro can be used only where a LABEL statement is allowed, in a data step or in certain PROCs. And even there, you have to use it in a way that results in valid SAS code being generated. Show us how you are using it. Show us the surrounding blocks of code and a larger part of the SASLOG.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Nov 2018 21:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/510014#M137199</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-03T21:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/510021#M137203</link>
      <description>&lt;P&gt;The full error messages are list below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MLOGIC(TTT): %DO loop index variable I is now 780; loop will iterate again.&lt;/P&gt;
&lt;P&gt;MLOGIC(TTT): %PUT &amp;amp;i&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable I resolves to 780&lt;/P&gt;
&lt;P&gt;780&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable I resolves to 780&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable SNAME780 resolves to CultureType4&lt;/P&gt;
&lt;P&gt;NOTE: Line generated by the invoked macro "TTT".&lt;/P&gt;
&lt;P&gt;1559 label &amp;amp;&amp;amp;sname&amp;amp;i="&amp;amp;&amp;amp;lname&amp;amp;i";&lt;/P&gt;
&lt;P&gt;-----&lt;/P&gt;
&lt;P&gt;180&lt;/P&gt;
&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: &amp;amp;&amp;amp; resolves to &amp;amp;.&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable I resolves to 780&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable LNAME780 resolves to CHART REVIEW 2 CultureType4: If&lt;/P&gt;
&lt;P&gt;other, specify&lt;/P&gt;
&lt;P&gt;MPRINT(TTT): label CultureType4="CHART REVIEW 2 CultureType4: If other, specify";&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 19:03:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/510021#M137203</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2018-11-02T19:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/510023#M137205</link>
      <description>&lt;P&gt;I said ... show us the surrounding blocks of code and a larger part of the SASLOG. Let's see the code. Let's see more of the SASLOG.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 19:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/510023#M137205</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-02T19:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/510178#M137283</link>
      <description>&lt;P&gt;Looks like the macro is working fine.&lt;/P&gt;
&lt;PRE&gt;MPRINT(TTT): label CultureType4="CHART REVIEW 2 CultureType4: If other, specify";&lt;/PRE&gt;
&lt;P&gt;You just need to call it in a place where LABEL is a valid statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  %ttt;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Nov 2018 15:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/510178#M137283</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-03T15:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/510207#M137301</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Looks like the macro is working fine.&lt;/P&gt;
&lt;PRE&gt;MPRINT(TTT): label CultureType4="CHART REVIEW 2 CultureType4: If other, specify";&lt;/PRE&gt;
&lt;P&gt;You just need to call it in a place where LABEL is a valid statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  %ttt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, this has already been pointed out to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;, and you can also find this in his partial log file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1561 label &amp;amp;&amp;amp;sname&amp;amp;i="&amp;amp;&amp;amp;lname&amp;amp;i";

-----

180&lt;/PRE&gt;
&lt;P&gt;so until we can see his code, AND a larger part of his SASLOG, we won't be able to figure out what is going on.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Nov 2018 21:11:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop/m-p/510207#M137301</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-11-03T21:11:35Z</dc:date>
    </item>
  </channel>
</rss>

