<?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: Concatenation in a data step do loop. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-in-a-data-step-do-loop/m-p/75718#M16322</link>
    <description>sorry that I can't explain why there is no blank in [pre] %put }}%gen( prefix=ABC, to=1 ){{; [/pre] and there is that one blank in [pre] %put }}%gen( prefix=ABC, to=3 ){{;[/pre] Should you really need to eliminate those blank separators, then wrap &amp;amp;prefix&amp;amp;i with %do ; and %end ;&lt;BR /&gt;
&lt;BR /&gt;
If for some reason, I needed to load a macro variable for multiple values of a variable in a data step, I would use call execute() inside that loop. For example a list of the boys names in the sashelp class data set to be stored in &amp;amp;mStudents[pre]data _null_ ;&lt;BR /&gt;
    call execute( '%nrstr( %%let mStudents =  )' ) ;&lt;BR /&gt;
    do while( not EOF ) ;&lt;BR /&gt;
       set sashelp.class( where=( sex='M' )) end= EOF ;&lt;BR /&gt;
       call execute(  name ) ;&lt;BR /&gt;
    end ;&lt;BR /&gt;
    call execute( ';' ) ;&lt;BR /&gt;
    stop ;&lt;BR /&gt;
 run; [/pre] The generated code should be single %let statement with a separate line for each iteration of the DO While loop. &lt;BR /&gt;
Generally I choose the simpler solution driven normally by the context or source of the information. For collecting names into a macro variable, I would be choosing proc sql. Not sure when I would choose that data step method, but must have needed it some time.&lt;BR /&gt;
 &lt;BR /&gt;
Good luck&lt;BR /&gt;
PeterC</description>
    <pubDate>Tue, 20 Apr 2010 13:47:54 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2010-04-20T13:47:54Z</dc:date>
    <item>
      <title>Concatenation in a data step do loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-in-a-data-step-do-loop/m-p/75714#M16318</link>
      <description>I want MYSTR="X1 X2 X3 ... X500". Here X4 to X499 left out for obvious reasons.&lt;BR /&gt;
&lt;BR /&gt;
This doesn't work:&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
length mystr $ 1892;&lt;BR /&gt;
mystr="X1";&lt;BR /&gt;
do i=2 to 500;&lt;BR /&gt;
mystr=mystr || " " || "X" || strip(put(i,3.0));&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
/* Here: Assign MYSTR to a macro variable with CALL SYMPUT for use in later data steps. */&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
MYSTR will be "X1".&lt;BR /&gt;
&lt;BR /&gt;
How do I solve this problem?</description>
      <pubDate>Tue, 20 Apr 2010 09:29:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenation-in-a-data-step-do-loop/m-p/75714#M16318</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-04-20T09:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenation in a data step do loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-in-a-data-step-do-loop/m-p/75715#M16319</link>
      <description>are you looking for &lt;BR /&gt;
%let xList = %gen( prefix= X, to= 500 )  ;&lt;BR /&gt;
where %gen is defined as the macro[pre]%macro gen( prefix=, from=1, to= 1, by=1 ) ;&lt;BR /&gt;
 %local i ;&lt;BR /&gt;
 %do    i= &amp;amp;from  %to &amp;amp;to  %by &amp;amp;by;&lt;BR /&gt;
&amp;amp;prefix&amp;amp;i &lt;BR /&gt;
 %end ;&lt;BR /&gt;
%mend  gen ; [/pre]&lt;BR /&gt;
 &lt;BR /&gt;
Why use a data step?</description>
      <pubDate>Tue, 20 Apr 2010 09:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenation-in-a-data-step-do-loop/m-p/75715#M16319</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-04-20T09:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenation in a data step do loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-in-a-data-step-do-loop/m-p/75716#M16320</link>
      <description>I think you are looking for &lt;BR /&gt;
&lt;BR /&gt;
call symput('mystr', CATX(' ', OF X1-X500));</description>
      <pubDate>Tue, 20 Apr 2010 12:22:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenation-in-a-data-step-do-loop/m-p/75716#M16320</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2010-04-20T12:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenation in a data step do loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-in-a-data-step-do-loop/m-p/75717#M16321</link>
      <description>Peter C&lt;BR /&gt;
&lt;BR /&gt;
Your code works. Can you explain how. Why do you get a blank between each Xn; n=1, ..., 500?&lt;BR /&gt;
&lt;BR /&gt;
Flip&lt;BR /&gt;
&lt;BR /&gt;
With your method I have to do like this:&lt;BR /&gt;
&lt;BR /&gt;
data _null_ ;&lt;BR /&gt;
array t(500) $;&lt;BR /&gt;
do i=1 to 500;&lt;BR /&gt;
t(i)="X" || strip(put(i,3.0));&lt;BR /&gt;
end;&lt;BR /&gt;
call symput('mystr', catx(' ',of t1-t500);&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 20 Apr 2010 13:06:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenation-in-a-data-step-do-loop/m-p/75717#M16321</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-04-20T13:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenation in a data step do loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-in-a-data-step-do-loop/m-p/75718#M16322</link>
      <description>sorry that I can't explain why there is no blank in [pre] %put }}%gen( prefix=ABC, to=1 ){{; [/pre] and there is that one blank in [pre] %put }}%gen( prefix=ABC, to=3 ){{;[/pre] Should you really need to eliminate those blank separators, then wrap &amp;amp;prefix&amp;amp;i with %do ; and %end ;&lt;BR /&gt;
&lt;BR /&gt;
If for some reason, I needed to load a macro variable for multiple values of a variable in a data step, I would use call execute() inside that loop. For example a list of the boys names in the sashelp class data set to be stored in &amp;amp;mStudents[pre]data _null_ ;&lt;BR /&gt;
    call execute( '%nrstr( %%let mStudents =  )' ) ;&lt;BR /&gt;
    do while( not EOF ) ;&lt;BR /&gt;
       set sashelp.class( where=( sex='M' )) end= EOF ;&lt;BR /&gt;
       call execute(  name ) ;&lt;BR /&gt;
    end ;&lt;BR /&gt;
    call execute( ';' ) ;&lt;BR /&gt;
    stop ;&lt;BR /&gt;
 run; [/pre] The generated code should be single %let statement with a separate line for each iteration of the DO While loop. &lt;BR /&gt;
Generally I choose the simpler solution driven normally by the context or source of the information. For collecting names into a macro variable, I would be choosing proc sql. Not sure when I would choose that data step method, but must have needed it some time.&lt;BR /&gt;
 &lt;BR /&gt;
Good luck&lt;BR /&gt;
PeterC</description>
      <pubDate>Tue, 20 Apr 2010 13:47:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenation-in-a-data-step-do-loop/m-p/75718#M16322</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-04-20T13:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenation in a data step do loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-in-a-data-step-do-loop/m-p/75719#M16323</link>
      <description>The blanks should be there.&lt;BR /&gt;
&lt;BR /&gt;
I'm just trying to understand how the code works.&lt;BR /&gt;
&lt;BR /&gt;
In "ordinary" programming it's very common in loops with expressions like&lt;BR /&gt;
&lt;BR /&gt;
X=X ¤ Y, where ¤ here represents some kind of function; X is updated each round of the loop.&lt;BR /&gt;
&lt;BR /&gt;
So I would like to know how your &amp;amp;prefix&amp;amp;i(=x&amp;amp;i) develops in the loop to: x1, x1 x2, x1 x2 x3, ..., and so on.</description>
      <pubDate>Tue, 20 Apr 2010 18:02:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenation-in-a-data-step-do-loop/m-p/75719#M16323</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-04-20T18:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenation in a data step do loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenation-in-a-data-step-do-loop/m-p/75720#M16324</link>
      <description>Hi:&lt;BR /&gt;
  If I needed to get a list of names into a macro variable, I'd be tempted to use PROC SQL.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select distinct name into :mStudents separated by ' '&lt;BR /&gt;
  from sashelp.class&lt;BR /&gt;
  where sex = 'M'&lt;BR /&gt;
  order by name;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
%put ------****** what is mStudents? &amp;amp;mstudents;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 20 Apr 2010 20:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenation-in-a-data-step-do-loop/m-p/75720#M16324</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-04-20T20:25:15Z</dc:date>
    </item>
  </channel>
</rss>

