<?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 recode same variables in different waves? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-recode-same-variables-in-different-waves/m-p/859070#M339430</link>
    <description>I don't know more about your analysis but I'd consider restructuring your data to have year be a variable and a row per year rather than multiple variable structure (long versus wide). Makes it much easier to do data manipulation for sure.</description>
    <pubDate>Wed, 15 Feb 2023 22:10:00 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2023-02-15T22:10:00Z</dc:date>
    <item>
      <title>How to recode same variables in different waves?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-recode-same-variables-in-different-waves/m-p/859056#M339421</link>
      <description>&lt;P&gt;I was wondering if there is any simple code to do the codes below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if (R9HIBP=1 or R9HIBPE =1) then highbp9=1; else highbp9=0;&lt;BR /&gt;if (R9DIAB =1 or R9DIABE =1) then diabetes9=1; else diabetes9=0;&lt;BR /&gt;if (R9CANCR =1 or R9CANCRE =1) then cancer9=1; else cancer9=0;&lt;BR /&gt;if (R9HEART =1 or R9HEARTE =1) then heartd9=1; else heartd9=0;&lt;BR /&gt;if (R9STROK =1 or R9STROKE =1) then stroke9=1; else stroke9=0;&lt;BR /&gt;if (R9lung =1 or R9lungE =1) then lung9=1; else lung9=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if (R10HIBP=1 or R10HIBPE =1) then highbp10=1; else highbp10=0;&lt;BR /&gt;if (R10DIAB =1 or R10DIABE =1) then diabetes10=1; else diabetes10=0;&lt;BR /&gt;if (R10CANCR =1 or R10CANCRE =1) then cancer10=1; else cancer10=0;&lt;BR /&gt;if (R10HEART =1 or R10HEARTE =1) then heartd10=1; else heartd10=0;&lt;BR /&gt;if (R10STROK =1 or R10STROKE =1) then stroke10=1; else stroke10=0;&lt;BR /&gt;if (R10lung =1 or R10lungE =1) then lung10=1; else lung10=0;&lt;BR /&gt;&lt;BR /&gt;if (R11HIBP=1 or R11HIBPE =1) then highbp11=1; else highbp11=0;&lt;BR /&gt;if (R11DIAB =1 or R11DIABE =1) then diabetes11=1; else diabetes11=0;&lt;BR /&gt;if (R11CANCR =1 or R11CANCRE =1) then cancer11=1; else cancer11=0;&lt;BR /&gt;if (R11HEART =1 or R11HEARTE =1) then heartd11=1; else heartd11=0;&lt;BR /&gt;if (R11STROK =1 or R11STROKE =1) then stroke11=1; else stroke11=0;&lt;BR /&gt;if (R11lung =1 or R11lungE =1) then lung11=1; else lung11=0;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 20:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-recode-same-variables-in-different-waves/m-p/859056#M339421</guid>
      <dc:creator>nwang5</dc:creator>
      <dc:date>2023-02-15T20:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to recode same variables in different waves?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-recode-same-variables-in-different-waves/m-p/859063#M339424</link>
      <description>If you have only three waves with the extra array statements and do loops you won't save much code wise.&lt;BR /&gt;&lt;BR /&gt;If you have more than three waves then switching to an array methodology would help.</description>
      <pubDate>Wed, 15 Feb 2023 21:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-recode-same-variables-in-different-waves/m-p/859063#M339424</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-02-15T21:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to recode same variables in different waves?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-recode-same-variables-in-different-waves/m-p/859070#M339430</link>
      <description>I don't know more about your analysis but I'd consider restructuring your data to have year be a variable and a row per year rather than multiple variable structure (long versus wide). Makes it much easier to do data manipulation for sure.</description>
      <pubDate>Wed, 15 Feb 2023 22:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-recode-same-variables-in-different-waves/m-p/859070#M339430</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-02-15T22:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to recode same variables in different waves?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-recode-same-variables-in-different-waves/m-p/859074#M339432</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439162"&gt;@nwang5&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I was wondering if there is any simple code to do the codes below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if (R9HIBP=1 or R9HIBPE =1) then highbp9=1; else highbp9=0;&lt;BR /&gt;if (R9DIAB =1 or R9DIABE =1) then diabetes9=1; else diabetes9=0;&lt;BR /&gt;if (R9CANCR =1 or R9CANCRE =1) then cancer9=1; else cancer9=0;&lt;BR /&gt;if (R9HEART =1 or R9HEARTE =1) then heartd9=1; else heartd9=0;&lt;BR /&gt;if (R9STROK =1 or R9STROKE =1) then stroke9=1; else stroke9=0;&lt;BR /&gt;if (R9lung =1 or R9lungE =1) then lung9=1; else lung9=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if (R10HIBP=1 or R10HIBPE =1) then highbp10=1; else highbp10=0;&lt;BR /&gt;if (R10DIAB =1 or R10DIABE =1) then diabetes10=1; else diabetes10=0;&lt;BR /&gt;if (R10CANCR =1 or R10CANCRE =1) then cancer10=1; else cancer10=0;&lt;BR /&gt;if (R10HEART =1 or R10HEARTE =1) then heartd10=1; else heartd10=0;&lt;BR /&gt;if (R10STROK =1 or R10STROKE =1) then stroke10=1; else stroke10=0;&lt;BR /&gt;if (R10lung =1 or R10lungE =1) then lung10=1; else lung10=0;&lt;BR /&gt;&lt;BR /&gt;if (R11HIBP=1 or R11HIBPE =1) then highbp11=1; else highbp11=0;&lt;BR /&gt;if (R11DIAB =1 or R11DIABE =1) then diabetes11=1; else diabetes11=0;&lt;BR /&gt;if (R11CANCR =1 or R11CANCRE =1) then cancer11=1; else cancer11=0;&lt;BR /&gt;if (R11HEART =1 or R11HEARTE =1) then heartd11=1; else heartd11=0;&lt;BR /&gt;if (R11STROK =1 or R11STROKE =1) then stroke11=1; else stroke11=0;&lt;BR /&gt;if (R11lung =1 or R11lungE =1) then lung11=1; else lung11=0;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, you can replace all these lines of data step code by a single macro call, for example:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#999999"&gt;data want;
set have;&lt;/FONT&gt;
&lt;STRONG&gt;%recode(9,11,HIghBP DIABetes CANCeR HEARTd STROKe LUNG)&lt;/STRONG&gt;
&lt;FONT color="#999999"&gt;run;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;after defining the macro, e.g., like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro recode(first, last, dis);
%local i j var rvar;
%do i=&amp;amp;first %to &amp;amp;last;
  %do j=1 %to %sysfunc(countw(&amp;amp;dis));
     %let var=%scan(&amp;amp;dis,&amp;amp;j);
     %let rvar=R&amp;amp;i%upcase(%sysfunc(compress(&amp;amp;var,,ku)));
     %unquote(%lowcase(&amp;amp;var)&amp;amp;i = (&amp;amp;rvar=1 | &amp;amp;rvar.E=1);)
  %end;
  %put;
%end;
%mend recode;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you supply the first and last wave number (?) and the "disease list" (with uppercase letters indicating how to form the abbreviated variable names) in the three macro parameters and the macro creates the assignment statements (which are equivalent to your IF-THEN/ELSE statements). You can use the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1dhqw0i5yj2m8n15opapnwteqra.htm" target="_blank" rel="noopener"&gt;MPRINT system option&lt;/A&gt; to see the generated code in the log:&lt;/P&gt;
&lt;PRE&gt;414   &lt;STRONG&gt;options mprint;&lt;/STRONG&gt;
415
416   data want;
417   set have;
418   %recode(9,11,HIghBP DIABetes CANCeR HEARTd STROKe LUNG)
MPRINT(RECODE):   highbp9 = (R9HIBP=1 | R9HIBPE=1);
MPRINT(RECODE):   diabetes9 = (R9DIAB=1 | R9DIABE=1);
MPRINT(RECODE):   cancer9 = (R9CANCR=1 | R9CANCRE=1);
MPRINT(RECODE):   heartd9 = (R9HEART=1 | R9HEARTE=1);
MPRINT(RECODE):   stroke9 = (R9STROK=1 | R9STROKE=1);
MPRINT(RECODE):   lung9 = (R9LUNG=1 | R9LUNGE=1);

MPRINT(RECODE):   highbp10 = (R10HIBP=1 | R10HIBPE=1);
MPRINT(RECODE):   diabetes10 = (R10DIAB=1 | R10DIABE=1);
MPRINT(RECODE):   cancer10 = (R10CANCR=1 | R10CANCRE=1);
MPRINT(RECODE):   heartd10 = (R10HEART=1 | R10HEARTE=1);
MPRINT(RECODE):   stroke10 = (R10STROK=1 | R10STROKE=1);
MPRINT(RECODE):   lung10 = (R10LUNG=1 | R10LUNGE=1);

MPRINT(RECODE):   highbp11 = (R11HIBP=1 | R11HIBPE=1);
MPRINT(RECODE):   diabetes11 = (R11DIAB=1 | R11DIABE=1);
MPRINT(RECODE):   cancer11 = (R11CANCR=1 | R11CANCRE=1);
MPRINT(RECODE):   heartd11 = (R11HEART=1 | R11HEARTE=1);
MPRINT(RECODE):   stroke11 = (R11STROK=1 | R11STROKE=1);
MPRINT(RECODE):   lung11 = (R11LUNG=1 | R11LUNGE=1);

419   run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I agree with &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879" target="_blank" rel="noopener"&gt;Reeza&lt;/A&gt; that a "long" data structure would likely simplify your code even more than just creating all these variable names in macro loops.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 22:22:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-recode-same-variables-in-different-waves/m-p/859074#M339432</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-02-15T22:22:43Z</dc:date>
    </item>
  </channel>
</rss>

