<?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 write this condition in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-this-condition-in-macro/m-p/575699#M162907</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;similarly like this step i have write 24 steps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if shcheck1 = 1 then do;&lt;BR /&gt;TERM =Strip(sb1_display);&lt;BR /&gt;CAT ='HISTORY' ;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;if shcheck2 = 1 then do;&lt;BR /&gt;TERM =Strip(sb2_display);&lt;BR /&gt;CAT ='HISTORY' ;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if shcheck3 = 1 then do;&lt;BR /&gt;TERM =Strip(sb3_display);&lt;BR /&gt;CAT ='HISTORY' ;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;is there any easy way to give it in a macro for the numbers changing till 24?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in adv&lt;/P&gt;</description>
    <pubDate>Tue, 23 Jul 2019 09:00:39 GMT</pubDate>
    <dc:creator>Aayushi_17</dc:creator>
    <dc:date>2019-07-23T09:00:39Z</dc:date>
    <item>
      <title>how to write this condition in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-this-condition-in-macro/m-p/575699#M162907</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;similarly like this step i have write 24 steps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if shcheck1 = 1 then do;&lt;BR /&gt;TERM =Strip(sb1_display);&lt;BR /&gt;CAT ='HISTORY' ;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;if shcheck2 = 1 then do;&lt;BR /&gt;TERM =Strip(sb2_display);&lt;BR /&gt;CAT ='HISTORY' ;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if shcheck3 = 1 then do;&lt;BR /&gt;TERM =Strip(sb3_display);&lt;BR /&gt;CAT ='HISTORY' ;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;is there any easy way to give it in a macro for the numbers changing till 24?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in adv&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 09:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-this-condition-in-macro/m-p/575699#M162907</guid>
      <dc:creator>Aayushi_17</dc:creator>
      <dc:date>2019-07-23T09:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to write this condition in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-this-condition-in-macro/m-p/575705#M162909</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need macro here. Not tested :&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 shcheck shcheck:;

    do over shcheck;
        if shcheck=1 then do;
            TERM=strip(vvaluex(cats('sb',_i_,'_display')));
            CAT="HISTORY";
            output; 
        end;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Jul 2019 09:09:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-this-condition-in-macro/m-p/575705#M162909</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-07-23T09:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to write this condition in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-this-condition-in-macro/m-p/575706#M162910</link>
      <description>&lt;P&gt;Good that you asked. Try to avoid SAS macro language until you're sufficiently familiar with SAS Base language.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Base SAS Arrays should give you what you need.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=_:);
  set have;
  array shchecks {*} shcheck1 - shcheck24;
  array sb_displays {*} sb1_display -- sb24_display;

  do _i=1 to dim(shchecks);
    if shchecks[_i] = 1 then
      do;
        TERM =Strip(sb_displays[_i]);
        CAT ='HISTORY';
        output;
      end;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally numbered variables have the number at the end as this makes them easy to reference.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In above code "sb&amp;lt;n&amp;gt;_display" got the numbering in the middle so here I couldn't just reference as a list.&lt;/P&gt;
&lt;P&gt;Assuming that the variables come one after another in the source dataset I've used the double dash notation. You need to check in your source data if my assumption is correct (use a proc contents on the source table with order=varnum; check in the result if the sb&amp;lt;n&amp;gt; variable really come one after the other with consecutive varnums). If the sb&amp;lt;n&amp;gt; vars are not in consecutive order then you need to write them explicitly in the array definition - like:&lt;/P&gt;
&lt;PRE&gt;array sb_displays {*} sb1_display sb2_display sb3_display ....;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Jul 2019 09:16:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-this-condition-in-macro/m-p/575706#M162910</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-07-23T09:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to write this condition in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-write-this-condition-in-macro/m-p/575739#M162919</link>
      <description>&lt;P&gt;thank you this one worked&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 11:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-write-this-condition-in-macro/m-p/575739#M162919</guid>
      <dc:creator>Aayushi_17</dc:creator>
      <dc:date>2019-07-23T11:13:33Z</dc:date>
    </item>
  </channel>
</rss>

