<?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 Using Array-Changing columns value of  '1' with different values for each columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Array-Changing-columns-value-of-1-with-different-values/m-p/749351#M235450</link>
    <description>&lt;P&gt;Hi All, I want to change values of my columns (Q1-5) where there is '1' with different values in each column i.e for Q1, 1 will be remain same as 1 but in col 2, for the value '1' will replace by 2 similarly col3, col 4, col 5 for the value of 1 will value be replaced by 3, 4, 5 as in "&lt;STRONG&gt;data want_1&lt;/STRONG&gt;". Finally i want the dataset from wider to longer n(as in &lt;STRONG&gt;Data want_2&lt;/STRONG&gt;). Probably using ARRAY:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Really appreciate your help! Akter&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data main;&lt;/STRONG&gt;&lt;BR /&gt;Input&amp;nbsp; ID Q1-Q5;&lt;BR /&gt;Datalines;&lt;BR /&gt;1 1 0 0 0 0&lt;BR /&gt;2 0 1 0 0 1&lt;BR /&gt;3 0 0 0 1 1&lt;BR /&gt;4 1 1 0 0 0&lt;BR /&gt;5 0 0 1 0 0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Data want_1;&lt;/STRONG&gt;&lt;BR /&gt;ID Q1 Q2 Q3 Q4 Q5&lt;BR /&gt;1&amp;nbsp; 1&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&lt;BR /&gt;2&amp;nbsp; 0&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 5&lt;BR /&gt;3&amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 5&lt;BR /&gt;4&amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp;0&lt;BR /&gt;5&amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data want_2:&lt;/STRONG&gt; &lt;BR /&gt;Id&amp;nbsp; New_Var&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; 5&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; 4&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; 5&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;5&amp;nbsp; &amp;nbsp; 3&lt;/P&gt;</description>
    <pubDate>Mon, 21 Jun 2021 18:39:12 GMT</pubDate>
    <dc:creator>Akter</dc:creator>
    <dc:date>2021-06-21T18:39:12Z</dc:date>
    <item>
      <title>Using Array-Changing columns value of  '1' with different values for each columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Array-Changing-columns-value-of-1-with-different-values/m-p/749351#M235450</link>
      <description>&lt;P&gt;Hi All, I want to change values of my columns (Q1-5) where there is '1' with different values in each column i.e for Q1, 1 will be remain same as 1 but in col 2, for the value '1' will replace by 2 similarly col3, col 4, col 5 for the value of 1 will value be replaced by 3, 4, 5 as in "&lt;STRONG&gt;data want_1&lt;/STRONG&gt;". Finally i want the dataset from wider to longer n(as in &lt;STRONG&gt;Data want_2&lt;/STRONG&gt;). Probably using ARRAY:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Really appreciate your help! Akter&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data main;&lt;/STRONG&gt;&lt;BR /&gt;Input&amp;nbsp; ID Q1-Q5;&lt;BR /&gt;Datalines;&lt;BR /&gt;1 1 0 0 0 0&lt;BR /&gt;2 0 1 0 0 1&lt;BR /&gt;3 0 0 0 1 1&lt;BR /&gt;4 1 1 0 0 0&lt;BR /&gt;5 0 0 1 0 0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Data want_1;&lt;/STRONG&gt;&lt;BR /&gt;ID Q1 Q2 Q3 Q4 Q5&lt;BR /&gt;1&amp;nbsp; 1&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&lt;BR /&gt;2&amp;nbsp; 0&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 5&lt;BR /&gt;3&amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 5&lt;BR /&gt;4&amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp;0&lt;BR /&gt;5&amp;nbsp; 0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data want_2:&lt;/STRONG&gt; &lt;BR /&gt;Id&amp;nbsp; New_Var&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; 5&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; 4&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; 5&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;5&amp;nbsp; &amp;nbsp; 3&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jun 2021 18:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Array-Changing-columns-value-of-1-with-different-values/m-p/749351#M235450</guid>
      <dc:creator>Akter</dc:creator>
      <dc:date>2021-06-21T18:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using Array-Changing columns value of  '1' with different values for each columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Array-Changing-columns-value-of-1-with-different-values/m-p/749353#M235452</link>
      <description>&lt;P&gt;Very simple application of an ARRAY.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data main;
  input id q1-q5;
datalines;
1 1 0 0 0 0
2 0 1 0 0 1
3 0 0 0 1 1
4 1 1 0 0 0
5 0 0 1 0 0
;

data want_1(drop=new_var) want_2(keep=id new_var);
  set main;
  array q q1-q5 ;
  do new_var=1 to dim(q);
    if q[new_var] then do;
       output want_2;
       q[new_var]=new_var;
    end;
  end;
  output want_1;
run;

proc print data=want_1;
  title 'want_1';
run;
proc print data=want_2;
  title 'want_2';
run;
title;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;want_1

Obs    id    q1    q2    q3    q4    q5

 1      1     1     0     0     0     0
 2      2     0     2     0     0     5
 3      3     0     0     0     4     5
 4      4     1     2     0     0     0
 5      5     0     0     3     0     0
&amp;#12;
want_2

Obs    id    new_var

 1      1       1
 2      2       2
 3      2       5
 4      3       4
 5      3       5
 6      4       1
 7      4       2
 8      5       3
&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Jun 2021 18:57:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Array-Changing-columns-value-of-1-with-different-values/m-p/749353#M235452</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-21T18:57:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using Array-Changing columns value of  '1' with different values for each columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Array-Changing-columns-value-of-1-with-different-values/m-p/749378#M235469</link>
      <description>&lt;P&gt;You can also use proc transpose. I am biased to use it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=main out=main_t;
	by id;
	var q1-q5;
run;

data main_t2;
	set main_t;
	if col1=0 then delete;
	new_var=substr(_name_,2);
	drop col1 _name_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Jun 2021 20:41:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Array-Changing-columns-value-of-1-with-different-values/m-p/749378#M235469</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-06-21T20:41:35Z</dc:date>
    </item>
  </channel>
</rss>

