<?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: Creating a new variable from multiple variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-from-multiple-variables/m-p/861519#M340317</link>
    <description>Thanks this worked great!</description>
    <pubDate>Tue, 28 Feb 2023 17:59:31 GMT</pubDate>
    <dc:creator>Beanpot</dc:creator>
    <dc:date>2023-02-28T17:59:31Z</dc:date>
    <item>
      <title>Creating a new variable from multiple variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-from-multiple-variables/m-p/861202#M340183</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a dataset which has multiple different variables which have the same values across the variables. It would look like this for example:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Obs&lt;/TD&gt;&lt;TD&gt;Var1&lt;/TD&gt;&lt;TD&gt;Var2&lt;/TD&gt;&lt;TD&gt;Var3&lt;/TD&gt;&lt;TD&gt;Var4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;TD&gt;B1&lt;/TD&gt;&lt;TD&gt;C1&lt;/TD&gt;&lt;TD&gt;D1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;B1&lt;/TD&gt;&lt;TD&gt;D1&lt;/TD&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;TD&gt;C1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;D1&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;C1&lt;/TD&gt;&lt;TD&gt;D1&lt;/TD&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I want to create a new variable for each value so that the new variable is a dichotomous yes/no variable but I'm not sure how to code this. For instance, I'd create a variable A1 where 1=yes and 0=no:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Obs&lt;/TD&gt;&lt;TD&gt;A1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for the help!&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2023 19:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-from-multiple-variables/m-p/861202#M340183</guid>
      <dc:creator>Beanpot</dc:creator>
      <dc:date>2023-02-27T19:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable from multiple variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-from-multiple-variables/m-p/861204#M340184</link>
      <description>&lt;P&gt;Assuming there is a relatively short list of possible values for VAR1-VAR4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    if whichc('A1',of var1-var4) then a1=1;
    else a1=0;
    /* REPEAT AS NEEDED */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2023 20:08:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-from-multiple-variables/m-p/861204#M340184</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-27T20:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable from multiple variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-from-multiple-variables/m-p/861209#M340185</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm='09'x truncover;
informat obs 8. var1-var4 $2.;
input obs Var1-Var4;
cards;
1	A1	B1	C1	D1
2	B1	D1	A1	C1
3	D1			
4	C1	D1	A1	
;
run;

proc transpose data=have out=long;
by obs;
var var1-var4;
run;

data long2;
set long;
where not missing(col1);
value=1;
run;

proc sort data=long2;
by obs col1;
run;

proc transpose data=long2 out=wide;
by obs;
id col1;
var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Transposing data tutorials:&lt;BR /&gt;Long to Wide:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Wide to Long:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;And sometimes a double transpose is needed for extra wide data sets:&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd" target="_blank"&gt;https://gist.github.com/statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2023 20:14:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-from-multiple-variables/m-p/861209#M340185</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-02-27T20:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new variable from multiple variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-from-multiple-variables/m-p/861519#M340317</link>
      <description>Thanks this worked great!</description>
      <pubDate>Tue, 28 Feb 2023 17:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-variable-from-multiple-variables/m-p/861519#M340317</guid>
      <dc:creator>Beanpot</dc:creator>
      <dc:date>2023-02-28T17:59:31Z</dc:date>
    </item>
  </channel>
</rss>

