<?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: How to use Macro to create variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Macro-to-create-variables/m-p/669074#M200668</link>
    <description>&lt;P&gt;You do not need a macro here, you need an array.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a tutorial on using Arrays in SAS&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-arrays/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-arrays/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA file;
set file;

array x(*) x1_1--x10_1;*assumes variables are in order;
array y(*) y1_1 --y10_1;*assumes variables are in order;

*set to missing;
M1 = .;

do i=1 to 10 while(M1 ne 1);
      if x(i) in (1:3) and y(i) &amp;gt;=70 and y(i) &amp;lt;= 100 then M1 =1;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/337650"&gt;@AmyH_01&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not familiar with using Macro, but I think macro can really help to generate powerful code in my scenario.&lt;/P&gt;
&lt;P&gt;So, I have variable X1_1 to X10_1, each of them has its match Y1_1 to Y10_1. I want to create MI=1 if the condition is matched.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA file;&lt;/P&gt;
&lt;P&gt;set file;&lt;/P&gt;
&lt;P&gt;IF X1_1 in (1:3) &amp;nbsp;&amp;amp; Y1_1&amp;gt;=70 &amp;amp; Y1_1&amp;lt;=100 then MI=1;&lt;/P&gt;
&lt;P&gt;IF X2_1 in (1:3) &amp;nbsp;&amp;amp; Y2_1&amp;gt;=70 &amp;amp; Y2_1&amp;lt;=100 then MI=1;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;IF X10_1 in (1:3) &amp;nbsp;&amp;amp; Y10_1&amp;gt;=70 &amp;amp; Y10_1&amp;lt;=100 then MI=1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wonder if anyone here can help me to use Macro to create my codes. Thank you so much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jul 2020 03:30:17 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-07-14T03:30:17Z</dc:date>
    <item>
      <title>How to use Macro to create variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Macro-to-create-variables/m-p/669073#M200667</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not familiar with using Macro, but I think macro can really help to generate powerful code in my scenario.&lt;/P&gt;&lt;P&gt;So, I have variable X1_1 to X10_1, each of them has its match Y1_1 to Y10_1. I want to create MI=1 if the condition is matched.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA file;&lt;/P&gt;&lt;P&gt;set file;&lt;/P&gt;&lt;P&gt;IF X1_1 in (1:3) &amp;nbsp;&amp;amp; Y1_1&amp;gt;=70 &amp;amp; Y1_1&amp;lt;=100 then MI=1;&lt;/P&gt;&lt;P&gt;IF X2_1 in (1:3) &amp;nbsp;&amp;amp; Y2_1&amp;gt;=70 &amp;amp; Y2_1&amp;lt;=100 then MI=1;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;IF X10_1 in (1:3) &amp;nbsp;&amp;amp; Y10_1&amp;gt;=70 &amp;amp; Y10_1&amp;lt;=100 then MI=1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wonder if anyone here can help me to use Macro to create my codes. Thank you so much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2020 03:15:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-Macro-to-create-variables/m-p/669073#M200667</guid>
      <dc:creator>AmyH_01</dc:creator>
      <dc:date>2020-07-14T03:15:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Macro to create variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Macro-to-create-variables/m-p/669074#M200668</link>
      <description>&lt;P&gt;You do not need a macro here, you need an array.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a tutorial on using Arrays in SAS&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-arrays/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-arrays/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA file;
set file;

array x(*) x1_1--x10_1;*assumes variables are in order;
array y(*) y1_1 --y10_1;*assumes variables are in order;

*set to missing;
M1 = .;

do i=1 to 10 while(M1 ne 1);
      if x(i) in (1:3) and y(i) &amp;gt;=70 and y(i) &amp;lt;= 100 then M1 =1;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/337650"&gt;@AmyH_01&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not familiar with using Macro, but I think macro can really help to generate powerful code in my scenario.&lt;/P&gt;
&lt;P&gt;So, I have variable X1_1 to X10_1, each of them has its match Y1_1 to Y10_1. I want to create MI=1 if the condition is matched.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA file;&lt;/P&gt;
&lt;P&gt;set file;&lt;/P&gt;
&lt;P&gt;IF X1_1 in (1:3) &amp;nbsp;&amp;amp; Y1_1&amp;gt;=70 &amp;amp; Y1_1&amp;lt;=100 then MI=1;&lt;/P&gt;
&lt;P&gt;IF X2_1 in (1:3) &amp;nbsp;&amp;amp; Y2_1&amp;gt;=70 &amp;amp; Y2_1&amp;lt;=100 then MI=1;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;IF X10_1 in (1:3) &amp;nbsp;&amp;amp; Y10_1&amp;gt;=70 &amp;amp; Y10_1&amp;lt;=100 then MI=1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wonder if anyone here can help me to use Macro to create my codes. Thank you so much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2020 03:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-Macro-to-create-variables/m-p/669074#M200668</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-14T03:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Macro to create variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Macro-to-create-variables/m-p/669077#M200670</link>
      <description>&lt;P&gt;I have just been&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'d. Too fast.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2020 03:36:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-Macro-to-create-variables/m-p/669077#M200670</guid>
      <dc:creator>ketpt42</dc:creator>
      <dc:date>2020-07-14T03:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Macro to create variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Macro-to-create-variables/m-p/669081#M200672</link>
      <description>Thank you so much, Reeza! I was doing the array at first but I forgot to put while (MI ne 1), that caused the result became a mess. Thank you so much for your great help!! I truly appreciate it!</description>
      <pubDate>Tue, 14 Jul 2020 03:49:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-Macro-to-create-variables/m-p/669081#M200672</guid>
      <dc:creator>AmyH_01</dc:creator>
      <dc:date>2020-07-14T03:49:48Z</dc:date>
    </item>
  </channel>
</rss>

