<?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: Transpose in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Transpose-to-wide-with-duplicate-values/m-p/784275#M81291</link>
    <description>&lt;P&gt;What is the desired end result, after the tranpose?&lt;/P&gt;</description>
    <pubDate>Mon, 06 Dec 2021 11:18:55 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-12-06T11:18:55Z</dc:date>
    <item>
      <title>Transpose to wide with duplicate values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Transpose-to-wide-with-duplicate-values/m-p/784265#M81290</link>
      <description>&lt;P&gt;Hi all,&lt;BR /&gt;&lt;BR /&gt;Does anyone let me know how to transpose a column values which has duplicates. Previously I used a table which is like below,&lt;BR /&gt;Val1 Val2&lt;BR /&gt;Abc 123&lt;BR /&gt;Def 567&lt;BR /&gt;Abc 908&lt;BR /&gt;Ghf 543&lt;BR /&gt;&lt;BR /&gt;I would like to transpose Val1 values as variables for that I wrote a code which gave me an error like.&lt;BR /&gt;Proc transpose data=have out=want ;&lt;BR /&gt;Id Val1;&lt;BR /&gt;var Val2;&lt;BR /&gt;Run;&lt;BR /&gt;Error: The ID value " Abc" occurs twice in input data set. Later on, I used LET keyword in proc transpose but has given me only the last occurrence as you can see my data though Val1 has duplicates their corresponding values Val2 has unique values. Please help me.&lt;BR /&gt;Thankyou.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2021 11:09:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Transpose-to-wide-with-duplicate-values/m-p/784265#M81290</guid>
      <dc:creator>Pandu2</dc:creator>
      <dc:date>2021-12-08T11:09:35Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Transpose-to-wide-with-duplicate-values/m-p/784275#M81291</link>
      <description>&lt;P&gt;What is the desired end result, after the tranpose?&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 11:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Transpose-to-wide-with-duplicate-values/m-p/784275#M81291</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-06T11:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Transpose-to-wide-with-duplicate-values/m-p/784770#M81302</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Here are two methods, first using transpose and the other proc iml */&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt; &lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* I have expanded your data to ensure it will work with additional rows and columns */
************; 
************ ;


Data raw;
input Val1$ Val2 val3 val4;
cards;
Abc 123   1123  1231
Def 567   2567  5672
Abc 908   3908  9083
Ghf 543   4543  5434
Ghf 643   5643  6435
Ghf 743   6743  7436
;
/* First method: the var names for dup id given unique names */
proc sort out=rawsrt;
	by val1;
run;
data have;
  set rawsrt;
  by val1;
  if not first.val1 then do;   
  n+1;
    val1=cats(val1,n);
  end;  
  else n=0;
run;

proc transpose data=have out=want(drop=_name_); 
	id val1;
	var val2 val3 val4;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ghosh_4-1638913603994.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66476iD4FC6B706244D8C3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ghosh_4-1638913603994.png" alt="ghosh_4-1638913603994.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* Assumption:  The transposed data will be imported into Excel */
/* Second method:  Create two datasets, one each for vars and data */
proc iml;
   use raw;
   read all var _CHAR_ into varnames;   
   read all var _NUM_ into values; 
   var1=varnames`;
   var2=values`; 
close;
show names;
print var1, var2 ;

/* create two data sets: variables and data, respectively  */
create vars from var1;
append from var1;
create nums from var2; 
append from var2;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ghosh_5-1638913660539.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66477iA520187962C96B5B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ghosh_5-1638913660539.png" alt="ghosh_5-1638913660539.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2021 21:54:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Transpose-to-wide-with-duplicate-values/m-p/784770#M81302</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2021-12-07T21:54:15Z</dc:date>
    </item>
  </channel>
</rss>

