<?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 use macro variable in array, do loop? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-array-do-loop/m-p/570303#M160797</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a categorical variable RESP like this '&lt;/P&gt;
&lt;TABLE class="table" style="width: 380px;" summary="Procedure Print: Data Set WORK.G8_M_19" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data" style="width: 369.091px;"&gt;AB++++B+BD+A++BCDB++++B++A+B++A++BC++B+B+D&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to recode the 42 columns into 42 numerical variables, such as&lt;/P&gt;
&lt;P&gt;if substr(RESP, 1, 1) = '+ ' then score1=1;&lt;/P&gt;
&lt;P&gt;else if&amp;nbsp;substr(RESP, 1, 1 )= '*' then score1=0;&lt;/P&gt;
&lt;P&gt;else&amp;nbsp;score1=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to code this using array and do loop?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!!&lt;/P&gt;</description>
    <pubDate>Mon, 01 Jul 2019 15:36:58 GMT</pubDate>
    <dc:creator>TX_STAR</dc:creator>
    <dc:date>2019-07-01T15:36:58Z</dc:date>
    <item>
      <title>how to use macro variable in array, do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-array-do-loop/m-p/570303#M160797</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a categorical variable RESP like this '&lt;/P&gt;
&lt;TABLE class="table" style="width: 380px;" summary="Procedure Print: Data Set WORK.G8_M_19" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data" style="width: 369.091px;"&gt;AB++++B+BD+A++BCDB++++B++A+B++A++BC++B+B+D&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to recode the 42 columns into 42 numerical variables, such as&lt;/P&gt;
&lt;P&gt;if substr(RESP, 1, 1) = '+ ' then score1=1;&lt;/P&gt;
&lt;P&gt;else if&amp;nbsp;substr(RESP, 1, 1 )= '*' then score1=0;&lt;/P&gt;
&lt;P&gt;else&amp;nbsp;score1=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to code this using array and do loop?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!!&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 15:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-array-do-loop/m-p/570303#M160797</guid>
      <dc:creator>TX_STAR</dc:creator>
      <dc:date>2019-07-01T15:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to use macro variable in array, do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-array-do-loop/m-p/570304#M160798</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/7661"&gt;@TX_STAR&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a categorical variable RESP like this '&lt;/P&gt;
&lt;TABLE class="table" style="width: 380px;" summary="Procedure Print: Data Set WORK.G8_M_19" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data" style="width: 369.091px;"&gt;AB++++B+BD+A++BCDB++++B++A+B++A++BC++B+B+D&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to recode the 42 columns into 42 numerical variables, such as&lt;/P&gt;
&lt;P&gt;if substr(RESP, 1, 1) = '+ ' then score1=1;&lt;/P&gt;
&lt;P&gt;else if&amp;nbsp;substr(RESP, 1, 1 )= '*' then score1=0;&lt;/P&gt;
&lt;P&gt;else&amp;nbsp;score1=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to code this using array and do loop?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't think macro variables would help with this at all.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array score [42] ;
  do i=1 to dim(score);
    score[i]= ('+'=char(resp,i));
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Jul 2019 15:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-array-do-loop/m-p/570304#M160798</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-01T15:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to use macro variable in array, do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-array-do-loop/m-p/570309#M160801</link>
      <description>&lt;P&gt;It seems to me that macro variables (or macros) are not needed here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	resp='AB++++B+BD+A++BCDB++++B++A+B++A++BC++B+B+D';
	array score score1-score42;
	do i=1 to length(Resp);
	    if substr(resp,i,1)='+' then score(i)=1;
		else if substr(resp,i,1)='*' then score(i)=0;
		else score(i)=0;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Jul 2019 15:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-array-do-loop/m-p/570309#M160801</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-01T15:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to use macro variable in array, do loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-array-do-loop/m-p/570316#M160804</link>
      <description>Thank you all. Both solutions work for me!!!</description>
      <pubDate>Mon, 01 Jul 2019 16:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-macro-variable-in-array-do-loop/m-p/570316#M160804</guid>
      <dc:creator>TX_STAR</dc:creator>
      <dc:date>2019-07-01T16:24:39Z</dc:date>
    </item>
  </channel>
</rss>

