<?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: Use Macro Variable Who's Value is Part of Existing Variable Name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478059#M123223</link>
    <description>&lt;P&gt;What are you going to do with these copies of the data that you couldn't do with the original data?&lt;/P&gt;
&lt;P&gt;For example instead of using one of these copies using code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=mjr_def_rank_1 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could instead just use the original dataset by using code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=mjr_def_cnts_x_ssr  (keep= nbr_ssr rvw_cnt mjr_rnk_1 rnk_opn_mjr_1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or this:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=mjr_def_cnts_x_ssr ;
  var nbr_ssr rvw_cnt mjr_rnk_1 rnk_opn_mjr_1 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;You can use a data step to generate code if you really wanted to do it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do i=1 to 8 ;
     call execute(cats('%nrstr(%pull_rank)(rnk_nbr=',i,')'));
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Jul 2018 22:20:53 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-07-13T22:20:53Z</dc:date>
    <item>
      <title>Use Macro Variable Who's Value is Part of Existing Variable Name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478051#M123217</link>
      <description>&lt;P&gt;I have a table of which consists of a unique identifier, a records count, and two sets of 8 fields that are numbered 1 through 8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to separate the one large table into 8 separate tables with the unique identifier, the record count, and the two fields with the same number.&amp;nbsp; I tried using a macro but it is not working and I don't know enough about macros to know how to do it properly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro pull_rank(rnk_nbr=);&lt;BR /&gt;&lt;BR /&gt;data mjr_def_rank_&amp;amp;rnk_nbr.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep nbr_ssr rvw_cnt mjr_rnk_&amp;amp;rnk_nbr rnk_opn_mjr_&amp;amp;rnk_nbr;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set mjr_def_cnts_x_ssr;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%mend pull_rank;&lt;BR /&gt;&lt;BR /&gt;%pull_rank(rnk_nbr=1);&lt;BR /&gt;%pull_rank(rnk_nbr=2)&lt;BR /&gt;%pull_rank(rnk_nbr=3)&lt;BR /&gt;%pull_rank(rnk_nbr=4)&lt;BR /&gt;%pull_rank(rnk_nbr=5)&lt;BR /&gt;%pull_rank(rnk_nbr=6)&lt;BR /&gt;%pull_rank(rnk_nbr=7)&lt;BR /&gt;%pull_rank(rnk_nbr=8)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am aware of do loops with n repetitions but have no experience with them.&amp;nbsp; Any help you could give me would be greatly appreciated.&amp;nbsp; I have had no in depth training so I apologize for the simplicity of my problem.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 21:51:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478051#M123217</guid>
      <dc:creator>neml_fm</dc:creator>
      <dc:date>2018-07-13T21:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: Use Macro Variable Who's Value is Part of Existing Variable Name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478052#M123218</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/221000"&gt;@neml_fm&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a table of which consists of a unique identifier, a records count, and two sets of 8 fields that are numbered 1 through 8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to separate the one large table into 8 separate tables with the unique identifier, the record count, and the two fields with the same number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is almost always a bad idea. Programming so much easier if everything is in one data set and you use BY statements to analyze the data by your variable rank_nbr. So, I believe this is a solution to your macro problem.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 21:56:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478052#M123218</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-13T21:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: Use Macro Variable Who's Value is Part of Existing Variable Name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478053#M123219</link>
      <description>&lt;P&gt;Paige,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So how do I get varA_1 and varB_1 by comparing it to rank_nbr where it equals 1?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 21:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478053#M123219</guid>
      <dc:creator>neml_fm</dc:creator>
      <dc:date>2018-07-13T21:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Use Macro Variable Who's Value is Part of Existing Variable Name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478054#M123220</link>
      <description>&lt;P&gt;I have no idea what this means.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 22:03:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478054#M123220</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-13T22:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: Use Macro Variable Who's Value is Part of Existing Variable Name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478059#M123223</link>
      <description>&lt;P&gt;What are you going to do with these copies of the data that you couldn't do with the original data?&lt;/P&gt;
&lt;P&gt;For example instead of using one of these copies using code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=mjr_def_rank_1 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could instead just use the original dataset by using code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=mjr_def_cnts_x_ssr  (keep= nbr_ssr rvw_cnt mjr_rnk_1 rnk_opn_mjr_1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or this:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=mjr_def_cnts_x_ssr ;
  var nbr_ssr rvw_cnt mjr_rnk_1 rnk_opn_mjr_1 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;You can use a data step to generate code if you really wanted to do it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do i=1 to 8 ;
     call execute(cats('%nrstr(%pull_rank)(rnk_nbr=',i,')'));
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 22:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478059#M123223</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-13T22:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Use Macro Variable Who's Value is Part of Existing Variable Name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478065#M123226</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/221000"&gt;@neml_fm&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Paige,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So how do I get varA_1 and varB_1 by comparing it to rank_nbr where it equals 1?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since your "example" doesn't reference varA_1 or varB_1 this is adding another layer of confusion to any issue.&lt;/P&gt;
&lt;P&gt;What does "get" mean in this context?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I have two sets of variables with similar names and I want to do something using them as pairs the typical approach is to use arrays which are short hand ways to reference groups of variables.&lt;/P&gt;
&lt;PRE&gt;data have;
   input id a1 b1 a2 b2;
datalines;
1 23 47 16 9
2 1.5 3.8 25 66
;
run;

data want;
   set have;
   array a a1-a2;
   array b b1-b2;
   array sum{2};
   do i = 1 to dim(a);
      sum[i] = a[i] + b[i];
   end;
run;&lt;/PRE&gt;
&lt;P&gt;If my dataset Have above had 15 a and 15 b variables that I want to sum I would change the a2, b2 and sum{2} to a15, b15 and sum{15};&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first two arrays will use defined variables in the list if they exist. The array sum creates variables sum1 sum2 ,,, sumx whatever the integer inside the {} might be.&lt;/P&gt;
&lt;P&gt;The do loop counts how many elements are in a and&amp;nbsp;uses the corresponding b to create the sum of the pair.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you could use your rank_nbr as the index value of the array element (the number inside the [ ]) . I think.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another thing the arrays might be used for is to restructure the data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data trans;
   set have;
   array a a1-a2;
   array b b1-b2;
   array sum{2};
   do i = 1 to dim(a);
      atrans= a[i];
      btrans= b[i];
      output;
   end;
   keep id i atrans btrans;
run;&lt;/PRE&gt;
&lt;P&gt;which reshapes the data so that ID has one a and one b value per row and an indicator (I) which of the pairs contributed to the current row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 22:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478065#M123226</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-13T22:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Use Macro Variable Who's Value is Part of Existing Variable Name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478066#M123227</link>
      <description>&lt;P&gt;This covers far too broad a range to be helpful:&amp;nbsp; "but it is not working"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What actually happens when you try the program you posted?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 22:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478066#M123227</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-13T22:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Use Macro Variable Who's Value is Part of Existing Variable Name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478078#M123232</link>
      <description>&lt;P&gt;Are you trying to change your data structure? It looks like you're either splitting your data for export or restructuring.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're splitting it for process, that's almost always unneccessary.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you think you really really need it, search "sas subset data" and you'll find many examples either on here or SAS blogs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/221000"&gt;@neml_fm&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a table of which consists of a unique identifier, a records count, and two sets of 8 fields that are numbered 1 through 8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to separate the one large table into 8 separate tables with the unique identifier, the record count, and the two fields with the same number.&amp;nbsp; I tried using a macro but it is not working and I don't know enough about macros to know how to do it properly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro pull_rank(rnk_nbr=);&lt;BR /&gt;&lt;BR /&gt;data mjr_def_rank_&amp;amp;rnk_nbr.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep nbr_ssr rvw_cnt mjr_rnk_&amp;amp;rnk_nbr rnk_opn_mjr_&amp;amp;rnk_nbr;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set mjr_def_cnts_x_ssr;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%mend pull_rank;&lt;BR /&gt;&lt;BR /&gt;%pull_rank(rnk_nbr=1);&lt;BR /&gt;%pull_rank(rnk_nbr=2)&lt;BR /&gt;%pull_rank(rnk_nbr=3)&lt;BR /&gt;%pull_rank(rnk_nbr=4)&lt;BR /&gt;%pull_rank(rnk_nbr=5)&lt;BR /&gt;%pull_rank(rnk_nbr=6)&lt;BR /&gt;%pull_rank(rnk_nbr=7)&lt;BR /&gt;%pull_rank(rnk_nbr=8)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am aware of do loops with n repetitions but have no experience with them.&amp;nbsp; Any help you could give me would be greatly appreciated.&amp;nbsp; I have had no in depth training so I apologize for the simplicity of my problem.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jul 2018 00:46:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478078#M123232</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-14T00:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: Use Macro Variable Who's Value is Part of Existing Variable Name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478079#M123233</link>
      <description>&lt;P&gt;And the actual answer to your question, try the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint mlogic;
%macro pull_rank(rnk_nbr=);

data mjr_def_rank_&amp;amp;rnk_nbr.;
&amp;nbsp; &amp;nbsp; &amp;nbsp; set mjr_def_cnts_x_ssr;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep nbr_ssr rvw_cnt mjr_rnk_&amp;amp;rnk_nbr. rnk_opn_mjr_&amp;amp;rnk_nbr.;
run;

%mend pull_rank;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If it doesn't work, post your full log from a single call.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/221000"&gt;@neml_fm&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a table of which consists of a unique identifier, a records count, and two sets of 8 fields that are numbered 1 through 8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to separate the one large table into 8 separate tables with the unique identifier, the record count, and the two fields with the same number.&amp;nbsp; I tried using a macro but it is not working and I don't know enough about macros to know how to do it properly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro pull_rank(rnk_nbr=);&lt;BR /&gt;&lt;BR /&gt;data mjr_def_rank_&amp;amp;rnk_nbr.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep nbr_ssr rvw_cnt mjr_rnk_&amp;amp;rnk_nbr rnk_opn_mjr_&amp;amp;rnk_nbr;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set mjr_def_cnts_x_ssr;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%mend pull_rank;&lt;BR /&gt;&lt;BR /&gt;%pull_rank(rnk_nbr=1);&lt;BR /&gt;%pull_rank(rnk_nbr=2)&lt;BR /&gt;%pull_rank(rnk_nbr=3)&lt;BR /&gt;%pull_rank(rnk_nbr=4)&lt;BR /&gt;%pull_rank(rnk_nbr=5)&lt;BR /&gt;%pull_rank(rnk_nbr=6)&lt;BR /&gt;%pull_rank(rnk_nbr=7)&lt;BR /&gt;%pull_rank(rnk_nbr=8)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am aware of do loops with n repetitions but have no experience with them.&amp;nbsp; Any help you could give me would be greatly appreciated.&amp;nbsp; I have had no in depth training so I apologize for the simplicity of my problem.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jul 2018 00:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-Macro-Variable-Who-s-Value-is-Part-of-Existing-Variable-Name/m-p/478079#M123233</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-14T00:49:43Z</dc:date>
    </item>
  </channel>
</rss>

