<?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 Transpose help needed? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transpose-help-needed/m-p/669343#M200776</link>
    <description>&lt;P&gt;Can anyone help me make one row out of the 3 rows below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input ID $10. Network $ Affl $ ;&lt;BR /&gt;datalines;&lt;BR /&gt;1598720000 HMOB A10&lt;BR /&gt;1598720000 CARE A11&lt;BR /&gt;1598720000 MAPO A12&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc print data=test;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output should be one row:&lt;/P&gt;&lt;P&gt;ID NETWORK1 AFF1 NETWORK2 AFFL2 NETWORK3 AFFL3&lt;BR /&gt;1598720000 HMOB A10 CARE A11 MAPO A12&lt;/P&gt;</description>
    <pubDate>Wed, 15 Jul 2020 00:00:58 GMT</pubDate>
    <dc:creator>asabou01</dc:creator>
    <dc:date>2020-07-15T00:00:58Z</dc:date>
    <item>
      <title>Transpose help needed?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-help-needed/m-p/669343#M200776</link>
      <description>&lt;P&gt;Can anyone help me make one row out of the 3 rows below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input ID $10. Network $ Affl $ ;&lt;BR /&gt;datalines;&lt;BR /&gt;1598720000 HMOB A10&lt;BR /&gt;1598720000 CARE A11&lt;BR /&gt;1598720000 MAPO A12&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc print data=test;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output should be one row:&lt;/P&gt;&lt;P&gt;ID NETWORK1 AFF1 NETWORK2 AFFL2 NETWORK3 AFFL3&lt;BR /&gt;1598720000 HMOB A10 CARE A11 MAPO A12&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2020 00:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-help-needed/m-p/669343#M200776</guid>
      <dc:creator>asabou01</dc:creator>
      <dc:date>2020-07-15T00:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose help needed?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-help-needed/m-p/669346#M200778</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Assumption1 - Transposition should be done for each group of ID values */
/* Assumption2 - Dataset is sorted by ID values */
data test;
infile datalines;
input ID $10. Network $ Affl $ ;
datalines;
1598720000 HMOB A10
1598720000 CARE A11
1598720000 MAPO A12
1598720001 HMOB A10
1598720001 CARE A11
1598720001 MAPO A12
;
run;

proc transpose data=test out=trans1(drop= _name_) prefix=network;
	var network;
	by id;
run;

proc transpose data=test out=trans2(drop=_name_) prefix=affl;
	var affl;
	by id;
run;

data trans;
	merge trans1 trans2;
	by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That's one way to do it using PROC TRANSPOSE. You can also use a data step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/" target="_self"&gt;Reshaping Data Long to Wide Using the Data Step&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/" target="_self"&gt;Reshaping Data Long to Wide Using PROC TRANSPOSE&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2020 01:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-help-needed/m-p/669346#M200778</guid>
      <dc:creator>ketpt42</dc:creator>
      <dc:date>2020-07-15T01:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose help needed?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-help-needed/m-p/669365#M200790</link>
      <description>&lt;P&gt;If there are always three obs, this can be done in a single step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set test;
   by id notsorted;

   length 
      Network1-Network3 $ 8
      Affl1-Affl3 $ 8
   ;
   retain Network1-Network3 Affl1-Affl3;

   array n[0:2] Network1-Network3;
   array a[0:2] Affl1-Affl3;
   
   if first.Id then do;
      call missing(of n[*]);
      call missing(of a[*]);
   end;

   n[mod(_n_, 3)] = Network;
   a[mod(_n_, 3)] = Affl;

   if last.Id then do;
      output;
   end;

   drop Affl Network;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The variable are not in the required order, but this is just a minor change in the length-statement.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2020 06:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-help-needed/m-p/669365#M200790</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-07-15T06:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose help needed?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-help-needed/m-p/669431#M200818</link>
      <description>&lt;P&gt;Merge Skill:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
infile datalines;
input ID : $10. Network $ Affl $ ;
datalines;
1598720000 HMOB A10
1598720000 CARE A11
1598720000 MAPO A12
;

data temp;
 set test;
 by id;
 if first.id then n=0;
 n+1;
run;
proc sql noprint nowarn;
select distinct catt('temp(where=(n=',n,') rename=(
Network=Network',n,' Affl=Affl',n,'))') into : merge separated by ' '
from temp
 order by n;
quit;
data want;
 merge &amp;amp;merge;
 by id;
 drop n;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Jul 2020 12:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-help-needed/m-p/669431#M200818</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-07-15T12:47:13Z</dc:date>
    </item>
  </channel>
</rss>

