<?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 60 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744258#M233148</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210474"&gt;@Mscarboncopy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This worked really well. Thank you.&lt;/P&gt;
&lt;P&gt;Is there a way to do this for data variables? The main variable in this case would be dates instead of 1 selected.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I think this needs clarification and an example.&lt;/P&gt;</description>
    <pubDate>Thu, 27 May 2021 18:15:31 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-05-27T18:15:31Z</dc:date>
    <item>
      <title>Creating a new Variable from 60</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744151#M233084</link>
      <description>&lt;P&gt;I have 60 variables (selected = 1, not selected = 0 VAR1 to VAR60) that I wanted to collapse into one variable with 60 keys (MAINVAR).&lt;/P&gt;&lt;P&gt;However, each one of my ids, could have more than 1 selected.&lt;/P&gt;&lt;P&gt;If I did a simple if then, it overwrites.&lt;/P&gt;&lt;P&gt;What is the most effective way of doing this?&lt;/P&gt;&lt;P&gt;It would then become a stacked file. Each id that has more than one variable selected would have multiple entries.&lt;/P&gt;&lt;P&gt;To make it a little bit more complex, for each selected there is a corresponding date var and also corresponding timing variable (past present selected not selected). However, I could do the same thing for the timing and the date variables, once I know how to do this (I think).&lt;/P&gt;&lt;P&gt;Example of what the datafile looks like now (leaving dates and timing out):&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;&amp;nbsp; VAR1 VAR2 VAR3 VAR4 VAR5 VAR6&amp;nbsp; &amp;nbsp;etc…&lt;/P&gt;&lt;P&gt;A &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;BR /&gt;B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;0&lt;/P&gt;&lt;P&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;D&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example of how it would be from the example above:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp;MAINVAR (keys 1-60)&lt;/P&gt;&lt;P&gt;A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;D&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;D&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/P&gt;&lt;P&gt;D&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 13:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744151#M233084</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-05-27T13:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new Variable from 60</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744155#M233086</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
Input id $ VAR1 VAR2 VAR3 VAR4 VAR5 VAR6 ;
cards;
A     1          0         1         1         0        0
B     0          1         0         0         0        0
C     1          1         1         1         0        0
D     0          0         0         1          1       1
;

data want;
    set have;
    array v var1-var6;
    do mainvar=1 to dim(v);
        if v(mainvar)=1 then output;
    end;
    keep id mainvar;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 May 2021 14:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744155#M233086</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-05-27T14:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new Variable from 60</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744156#M233087</link>
      <description>&lt;P&gt;This has DATA step with a do loop written all over it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;iterate (using a do loop) over all the VARs&amp;nbsp; (use an array)&lt;/LI&gt;
&lt;LI&gt;If the array element is 1 then
&lt;OL&gt;
&lt;LI&gt;assign the element-number within the array to MAINVAR&lt;/LI&gt;
&lt;LI&gt;output the result&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (keep=id mainvar);
  set have;
  array _var {*} var: ;
  do mainvar=1 to dim(_var);
    if _var{mainvar}&amp;gt;0 then output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This relies entirely on the assumption that variable names range from VAR1 through VARxx, (xx=60 in your example) with no missing names in that list.&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 14:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744156#M233087</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-05-27T14:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new Variable from 60</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744176#M233101</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This has DATA step with a do loop written all over it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;iterate (using a do loop) over all the VARs&amp;nbsp; (use an array)&lt;/LI&gt;
&lt;LI&gt;If the array element is 1 then
&lt;OL&gt;
&lt;LI&gt;assign the element-number within the array to MAINVAR&lt;/LI&gt;
&lt;LI&gt;output the result&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (keep=id mainvar);
  set have;
  array _var {*} var: ;
  do mainvar=1 to dim(_var);
    if _var{mainvar}&amp;gt;0 then output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This relies entirely on the assumption that variable names range from VAR1 through VARxx, (xx=60 in your example) with no missing names in that list.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't think missing variable names in the VAR1 through VARxx is a problem in your code. I think actually it would be a problem in my code, but that's easily fixed.&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 14:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744176#M233101</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-05-27T14:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new Variable from 60</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744181#M233104</link>
      <description>&lt;P&gt;Here's some references you may find useful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Transposing data tutorials:&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;</description>
      <pubDate>Thu, 27 May 2021 14:59:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744181#M233104</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-27T14:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new Variable from 60</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744197#M233118</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This has DATA step with a do loop written all over it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;iterate (using a do loop) over all the VARs&amp;nbsp; (use an array)&lt;/LI&gt;
&lt;LI&gt;If the array element is 1 then
&lt;OL&gt;
&lt;LI&gt;assign the element-number within the array to MAINVAR&lt;/LI&gt;
&lt;LI&gt;output the result&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (keep=id mainvar);
  set have;
  array _var {*} var: ;
  do mainvar=1 to dim(_var);
    if _var{mainvar}&amp;gt;0 then output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This relies entirely on the assumption that variable names range from VAR1 through VARxx, (xx=60 in your example) with no missing names in that list.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't think missing variable names in the VAR1 through VARxx is a problem in your code. I think actually it would be a problem in my code, but that's easily fixed.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What I was trying to warn against was starting out with, say&amp;nbsp; VAR1 VAR2 VAR5 VAR6.&amp;nbsp; &amp;nbsp;They would form a 4-element array, with MAINVAR=3 for VAR5, and MAINVAR=4 for VAR6.&amp;nbsp; &amp;nbsp;Of course, I could avoid that problem by changing&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array _var {*} var: ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array _var {*} var1-var60 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is what I should have done to begin with.&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 15:50:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744197#M233118</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-05-27T15:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new Variable from 60</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744253#M233146</link>
      <description>&lt;P&gt;This worked really well. Thank you.&lt;/P&gt;&lt;P&gt;Is there a way to do this for data variables? The main variable in this case would be dates instead of 1 selected.&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 18:01:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744253#M233146</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-05-27T18:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new Variable from 60</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744254#M233147</link>
      <description>&lt;P&gt;I don't have missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 18:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744254#M233147</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-05-27T18:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new Variable from 60</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744258#M233148</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210474"&gt;@Mscarboncopy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This worked really well. Thank you.&lt;/P&gt;
&lt;P&gt;Is there a way to do this for data variables? The main variable in this case would be dates instead of 1 selected.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I think this needs clarification and an example.&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 18:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-Variable-from-60/m-p/744258#M233148</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-05-27T18:15:31Z</dc:date>
    </item>
  </channel>
</rss>

