<?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 Manipulating a macro variable list in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-a-macro-variable-list/m-p/36706#M7224</link>
    <description>Hi all, &lt;BR /&gt;
&lt;BR /&gt;
I have a macro [ %reg] where I have an argument [varlist] which is a variable list. This will contain variable names, delimited by a blank or blanks, and the total number of variable names passed to varlist itself can vary. &lt;BR /&gt;
&lt;BR /&gt;
A simple version of my code looks like this: &lt;BR /&gt;
&lt;BR /&gt;
----------------------------------------------------------------------------&lt;BR /&gt;
data a; &lt;BR /&gt;
input y x1 x2 x3 x4_old x4_new;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 8 7 2 4 7 &lt;BR /&gt;
3 4 6 2 7 2 &lt;BR /&gt;
9 0 2 1 7 -9 &lt;BR /&gt;
9 5 3 8 7 0&lt;BR /&gt;
0 9 8 3 5 -7&lt;BR /&gt;
;&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
options symbolgen; &lt;BR /&gt;
%macro lin(method,varlist);&lt;BR /&gt;
proc reg data =a;&lt;BR /&gt;
model y = &amp;amp;varlist/&amp;amp;method; &lt;BR /&gt;
run; &lt;BR /&gt;
%let varcnt=%sysfunc(countw(&amp;amp;varlist));&lt;BR /&gt;
%put There are &amp;amp;varcnt variables in the model; &lt;BR /&gt;
data _null_;&lt;BR /&gt;
set a;&lt;BR /&gt;
%do i=1 %to &amp;amp;varcnt;  &lt;BR /&gt;
%let var&amp;amp;i =%qscan(&amp;amp;varlist,&amp;amp;i);&lt;BR /&gt;
%put var&amp;amp;i = &amp;amp;&amp;amp;var&amp;amp;i; &lt;BR /&gt;
%end; &lt;BR /&gt;
run; &lt;BR /&gt;
%mend lin;&lt;BR /&gt;
--------------------------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
%lin(all, x1 x2 x4_old); &amp;gt; invoking the macro in this way gives desired results. &lt;BR /&gt;
&lt;BR /&gt;
Now, I want to put in a sum statement like the following :&lt;BR /&gt;
&lt;BR /&gt;
z=sum( all the variables that are in varlist). &lt;BR /&gt;
&lt;BR /&gt;
eg z = sum(x1,x2,x4_old) ; &lt;BR /&gt;
&lt;BR /&gt;
Obviously, I need a comma seperated variable list. Can any one please show me the quickest way to do this? Thanks a lot for your help!!&lt;BR /&gt;
&lt;BR /&gt;
Best, wbguy</description>
    <pubDate>Fri, 19 Nov 2010 00:07:05 GMT</pubDate>
    <dc:creator>wbguy</dc:creator>
    <dc:date>2010-11-19T00:07:05Z</dc:date>
    <item>
      <title>Manipulating a macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-a-macro-variable-list/m-p/36706#M7224</link>
      <description>Hi all, &lt;BR /&gt;
&lt;BR /&gt;
I have a macro [ %reg] where I have an argument [varlist] which is a variable list. This will contain variable names, delimited by a blank or blanks, and the total number of variable names passed to varlist itself can vary. &lt;BR /&gt;
&lt;BR /&gt;
A simple version of my code looks like this: &lt;BR /&gt;
&lt;BR /&gt;
----------------------------------------------------------------------------&lt;BR /&gt;
data a; &lt;BR /&gt;
input y x1 x2 x3 x4_old x4_new;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 8 7 2 4 7 &lt;BR /&gt;
3 4 6 2 7 2 &lt;BR /&gt;
9 0 2 1 7 -9 &lt;BR /&gt;
9 5 3 8 7 0&lt;BR /&gt;
0 9 8 3 5 -7&lt;BR /&gt;
;&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
options symbolgen; &lt;BR /&gt;
%macro lin(method,varlist);&lt;BR /&gt;
proc reg data =a;&lt;BR /&gt;
model y = &amp;amp;varlist/&amp;amp;method; &lt;BR /&gt;
run; &lt;BR /&gt;
%let varcnt=%sysfunc(countw(&amp;amp;varlist));&lt;BR /&gt;
%put There are &amp;amp;varcnt variables in the model; &lt;BR /&gt;
data _null_;&lt;BR /&gt;
set a;&lt;BR /&gt;
%do i=1 %to &amp;amp;varcnt;  &lt;BR /&gt;
%let var&amp;amp;i =%qscan(&amp;amp;varlist,&amp;amp;i);&lt;BR /&gt;
%put var&amp;amp;i = &amp;amp;&amp;amp;var&amp;amp;i; &lt;BR /&gt;
%end; &lt;BR /&gt;
run; &lt;BR /&gt;
%mend lin;&lt;BR /&gt;
--------------------------------------------------------------------------&lt;BR /&gt;
&lt;BR /&gt;
%lin(all, x1 x2 x4_old); &amp;gt; invoking the macro in this way gives desired results. &lt;BR /&gt;
&lt;BR /&gt;
Now, I want to put in a sum statement like the following :&lt;BR /&gt;
&lt;BR /&gt;
z=sum( all the variables that are in varlist). &lt;BR /&gt;
&lt;BR /&gt;
eg z = sum(x1,x2,x4_old) ; &lt;BR /&gt;
&lt;BR /&gt;
Obviously, I need a comma seperated variable list. Can any one please show me the quickest way to do this? Thanks a lot for your help!!&lt;BR /&gt;
&lt;BR /&gt;
Best, wbguy</description>
      <pubDate>Fri, 19 Nov 2010 00:07:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-a-macro-variable-list/m-p/36706#M7224</guid>
      <dc:creator>wbguy</dc:creator>
      <dc:date>2010-11-19T00:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating a macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-a-macro-variable-list/m-p/36707#M7225</link>
      <description>Use the TRANSPOSE function and do it in macro code with also using the %SYSFUNC(....) macro call function in a %LET statement.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
sysfunc data step using function call site:sas.com</description>
      <pubDate>Fri, 19 Nov 2010 01:25:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-a-macro-variable-list/m-p/36707#M7225</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-11-19T01:25:49Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating a macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-a-macro-variable-list/m-p/36708#M7226</link>
      <description>Obviously. You need another style of sum function.&lt;BR /&gt;
[pre]&lt;BR /&gt;
_sum=sum( of weight height age);&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Fri, 19 Nov 2010 02:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-a-macro-variable-list/m-p/36708#M7226</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-11-19T02:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating a macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-a-macro-variable-list/m-p/36709#M7227</link>
      <description>The sum function seems to be the simplest way to accomplish what I want......thanks a lot!!!</description>
      <pubDate>Fri, 19 Nov 2010 03:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-a-macro-variable-list/m-p/36709#M7227</guid>
      <dc:creator>wbguy</dc:creator>
      <dc:date>2010-11-19T03:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: Manipulating a macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Manipulating-a-macro-variable-list/m-p/36710#M7228</link>
      <description>...&lt;BR /&gt;
&amp;gt; Obviously, I need a comma seperated variable list.&lt;BR /&gt;
&amp;gt; Can any one please show me the quickest way to do&lt;BR /&gt;
&amp;gt; this? Thanks a lot for your help!!&lt;BR /&gt;
...&lt;BR /&gt;
Here is a simple macro that converts input blank separated list into a comma separated list. Hope this helps a bit.&lt;BR /&gt;
[pre]&lt;BR /&gt;
   %macro b2c(src);&lt;BR /&gt;
     %local comma blank;&lt;BR /&gt;
     %let comma = %str(,);&lt;BR /&gt;
     %let blank = %str( );&lt;BR /&gt;
     %let src = %sysfunc(strip(&amp;amp;src));&lt;BR /&gt;
     %sysfunc(translate(&amp;amp;src,&amp;amp;comma,&amp;amp;blank))&lt;BR /&gt;
   %mend  b2c;&lt;BR /&gt;
&lt;BR /&gt;
   %put ***%b2c(x y z)***;&lt;BR /&gt;
   %*-- on log&lt;BR /&gt;
   ***x,y,z***&lt;BR /&gt;
   --*;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 07 Dec 2010 21:41:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Manipulating-a-macro-variable-list/m-p/36710#M7228</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2010-12-07T21:41:36Z</dc:date>
    </item>
  </channel>
</rss>

