<?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 how to replace those numbers with macro or do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376080#M90208</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO DO_LIST; %DO I = 1 %TO 8;
data sal&amp;amp;i.;
set sal ;
where  substr(year,4,1) ="&amp;amp;i" and num=&amp;amp;i;
run;




%END;
%MEND DO_LIST;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It works well with individual files. I&amp;nbsp;think I need to make&amp;nbsp;it more&amp;nbsp;efficiently by replacing these numbers with do loop or sas macro. They are just&amp;nbsp;numbers &amp;nbsp;from 1 to 8. When I ran it, it did not generates those datasets I need.&lt;/P&gt;
&lt;P&gt;Any advice? Thank you.&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jul 2017 15:58:53 GMT</pubDate>
    <dc:creator>Bal23</dc:creator>
    <dc:date>2017-07-14T15:58:53Z</dc:date>
    <item>
      <title>how to replace those numbers with macro or do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376080#M90208</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO DO_LIST; %DO I = 1 %TO 8;
data sal&amp;amp;i.;
set sal ;
where  substr(year,4,1) ="&amp;amp;i" and num=&amp;amp;i;
run;




%END;
%MEND DO_LIST;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It works well with individual files. I&amp;nbsp;think I need to make&amp;nbsp;it more&amp;nbsp;efficiently by replacing these numbers with do loop or sas macro. They are just&amp;nbsp;numbers &amp;nbsp;from 1 to 8. When I ran it, it did not generates those datasets I need.&lt;/P&gt;
&lt;P&gt;Any advice? Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 15:58:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376080#M90208</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2017-07-14T15:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace those numbers with macro or do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376084#M90211</link>
      <description>&lt;P&gt;Working or not, you are trying to generate an inefficient program here. &amp;nbsp;The macro generates code like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data sal1;&lt;/P&gt;
&lt;P&gt;set sal;&lt;/P&gt;
&lt;P&gt;where substr(year, 4, 1) = "1" and num=1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data sal2;&lt;/P&gt;
&lt;P&gt;set sal;&lt;/P&gt;
&lt;P&gt;where substr(year, 4, 1) = "2" and num=2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;data sal8;&lt;/P&gt;
&lt;P&gt;set sal;&lt;/P&gt;
&lt;P&gt;where substr(year, 4, 1) = "8" and num=8;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, consider whether this is the right code to produce the data sets you are seeking. &amp;nbsp;Then consider that this program has to read the data set SAL 8 times. &amp;nbsp;If you were to eliminate the macro language, you could certainly come up with a program that read the data set SAL once instead of 8 times, while creating 8 output data sets. &amp;nbsp;Once you design that program, you will have a prototype that you can use for rewriting the macro to make it more efficient.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 16:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376084#M90211</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-14T16:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace those numbers with macro or do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376088#M90214</link>
      <description>&lt;P&gt;you are right, i do need to generate 8 datasets,&lt;/P&gt;
&lt;P&gt;i need to select each different row for different year&lt;/P&gt;
&lt;P&gt;any other advice instead of using macro?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 16:12:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376088#M90214</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2017-07-14T16:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace those numbers with macro or do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376090#M90216</link>
      <description>&lt;P&gt;Absolutely. &amp;nbsp;I assume you are using a macro, then, because you don't know that SAS will let you create multiple data sets in a single step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data sal1 sal2 sal3 sal4 sal5 sal6 sal7 sal8;&lt;/P&gt;
&lt;P&gt;set sal;&lt;/P&gt;
&lt;P&gt;length first_digit $ 1;&lt;/P&gt;
&lt;P&gt;first_digit = year;&lt;/P&gt;
&lt;P&gt;if first_digit="1" and num=1 then output sal1;&lt;/P&gt;
&lt;P&gt;else if first_digit="2" and num=2 then output sal2;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;else if first_digit="8" and num=8 then output sal8;&lt;/P&gt;
&lt;P&gt;drop first_digit;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Such a program can be generated with macro language, but it's important to establish that the logic of the program is correct first.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 16:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376090#M90216</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-14T16:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace those numbers with macro or do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376093#M90217</link>
      <description>&lt;P&gt;this centainly works, but I have to type each line. and my final output will be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data salfinal;&lt;/P&gt;
&lt;P&gt;set sal1 sal2 sal3 sal4 sal5 sal6 sal7 sal8;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;any other advice?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 16:24:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376093#M90217</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2017-07-14T16:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace those numbers with macro or do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376095#M90218</link>
      <description>&lt;P&gt;Definitely. &amp;nbsp;There's still a lot of copying of data sets going on. &amp;nbsp;It looks like you don't care about the data sets sal1 through sal8, and all you really need is salfinal. &amp;nbsp;Is that right? &amp;nbsp;And would this program properly create the data set you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the answer is yes to everything, we can talk about macro language so that you won't have to type so much.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 16:32:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376095#M90218</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-14T16:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace those numbers with macro or do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376098#M90220</link>
      <description>&lt;P&gt;yes, I just need the salfinal dataset. I think if sas macro can be used, there would not be so many lines&lt;/P&gt;
&lt;P&gt;thank you&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 16:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376098#M90220</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2017-07-14T16:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace those numbers with macro or do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376108#M90224</link>
      <description>&lt;P&gt;Isn't all that logic equivalent to a single data step below?&lt;/P&gt;
&lt;P&gt;You're checking for the num in 1 to 8 and if the first digit equals the variable Num?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sal_final;
set sal;

first_digit=year;
first_char =char(first_digit, 1);
first_char_num = input(first_char, 8.);

if first_char_num eq num and first_char_num in (1:8);

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Jul 2017 17:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/376108#M90224</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-14T17:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace those numbers with macro or do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/378743#M91085</link>
      <description>&lt;P&gt;this worked very well if the numbers are from 1 to 8.&lt;/P&gt;
&lt;P&gt;what if the number list includes more numbers, such as two digit numbers?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my actual number list will be 1,2,3, 4, 5, 6, 12,13,22,23; would you please let me know how to modify your code?&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 16:57:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/378743#M91085</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2017-07-24T16:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace those numbers with macro or do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/378763#M91090</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/40773"&gt;@Bal23&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;this worked very well if the numbers are from 1 to 8.&lt;/P&gt;
&lt;P&gt;what if the number list includes more numbers, such as two digit numbers?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my actual number list will be 1,2,3, 4, 5, 6, 12,13,22,23; would you please let me know how to modify your code?&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You need to explain better what you have. For example is YEAR varaible character or numeric? If it is character then perhaps you just want to use the : modifier in your comparison?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have;
  if year in: ('1','2','3', '4', '5', '6', '12','13','22','23');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;But then why would you include '12','13','22' and '23' as separate items in the list since they would already be covered already by '1' and '2'. &amp;nbsp;A value that starts with '12' also starts with '1'.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 18:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/378763#M91090</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-24T18:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace those numbers with macro or do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/378768#M91093</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/40773"&gt;@Bal23&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;this worked very well if the numbers are from 1 to 8.&lt;/P&gt;
&lt;P&gt;what if the number list includes more numbers, such as two digit numbers?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my actual number list will be 1,2,3, 4, 5, 6, 12,13,22,23; would you please let me know how to modify your code?&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm not sure without seeing more data. Provide more details if you want further assistance.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 18:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-replace-those-numbers-with-macro-or-do-loop/m-p/378768#M91093</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-24T18:56:50Z</dc:date>
    </item>
  </channel>
</rss>

