<?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: Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/601443#M173969</link>
    <description>&lt;P&gt;When you want to perform the same task(s) on multiple columns, you use ARRAYs in a data step and you would NOT use macros. This is exactly the situation where ARRAYs are meant for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array item item1-item100;
    do i=1 to dim(item);
        if missing(item(i)) then item(i)=0; 
        else if item(i)&amp;gt;=500 then item(i)=500;
    end;
    drop i;
run;&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Nov 2019 17:50:33 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-11-04T17:50:33Z</dc:date>
    <item>
      <title>Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/601441#M173968</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I would like to ask a question please about &lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: 'HelevticaNeue-light','Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;one statement that need to repeat on multiple variables&lt;/SPAN&gt;.&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Way1*/
If item1 eq . then item1 = 0 ;
If item2 eq . then item2 = 0 ;
If item3 eq . then item3 = 0 ; 
and so on
If item100 eq . then item100 = 0 ; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT&gt;&lt;FONT&gt;&lt;CODE class=" language-sas"&gt;&lt;FONT&gt;/*Way2*/&lt;/FONT&gt;&lt;BR /&gt;%macro   check;&lt;BR /&gt;
%do i = 1 to 100;&lt;BR /&gt; 
if   item&amp;amp;i   eq .   then item&amp;amp;i = 0;&lt;BR /&gt;
%end check ; &lt;/CODE&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT&gt;&lt;FONT&gt;My question is how to do it when there are multiple statements that need to repeat.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;&lt;FONT&gt;for example:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Way1*/
If item1 eq . then item1 = 0 ;else IF item1&amp;gt;=500 then item1=500;
If item2 eq . then item2 = 0 ;else IF item2&amp;gt;=500 then item2=500;
If item3 eq . then item3 = 0 ; else IF item3&amp;gt;=500 then item3=500;
and so on
If item100  eq . then item100 = 0 ; else IF item100&amp;gt;=500 then item100=500;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT&gt;&lt;FONT&gt;But what is the way to do it via macro???&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Way2*/
%macro check;
%do i = 1 to 100;
if item&amp;amp;i eq . then item&amp;amp;i = 0;
else IF item&amp;amp;i&amp;gt;=500 then   item&amp;amp;i=500;
%end check ;&lt;/CODE&gt;&lt;/PRE&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know how to use macr&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 17:42:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/601441#M173968</guid>
      <dc:creator>DaveStar</dc:creator>
      <dc:date>2019-11-04T17:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/601443#M173969</link>
      <description>&lt;P&gt;When you want to perform the same task(s) on multiple columns, you use ARRAYs in a data step and you would NOT use macros. This is exactly the situation where ARRAYs are meant for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array item item1-item100;
    do i=1 to dim(item);
        if missing(item(i)) then item(i)=0; 
        else if item(i)&amp;gt;=500 then item(i)=500;
    end;
    drop i;
run;&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2019 17:50:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/601443#M173969</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-04T17:50:33Z</dc:date>
    </item>
  </channel>
</rss>

