<?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: Proc transpose to transform dataset from long to wide in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Proc-transpose-to-transform-dataset-from-long-to-wide/m-p/764666#M30499</link>
    <description>&lt;P&gt;The simplest way is using PROC SUMMARY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input id visit_num diag$ age treatment;
cards;
01 1 diabetes 42 1
02 1 stroke 78 1
02 2 cancer . 2
02 3 stroke . .
03 1 stroke 66 2
03 2 copd . 1
03 3 . . .
;
run;

proc sql noprint;
select max(n) into :n
 from (select count(*) as n from have group by id);
quit;
proc summary data=have;
by id;
output out=want idgroup(out[&amp;amp;n] (visit_num diag age treatment)=);
run;&lt;/PRE&gt;</description>
    <pubDate>Sun, 29 Aug 2021 11:20:13 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2021-08-29T11:20:13Z</dc:date>
    <item>
      <title>Proc transpose to transform dataset from long to wide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-transpose-to-transform-dataset-from-long-to-wide/m-p/764646#M30497</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;I am trying to use proc transpose to change my dataset from long to wide. Below is an example of my data and my desired output, as well as the code I have attempted so far. My issue is that when I run my code, the visit_num columns of the transposed dataset do not contain the diag values. I'm wondering how to fix my code so I can get my desired output (and how to keep the Age variable from the original dataset).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id visit_num diag$ age treatment;
cards;
01 1 diabetes 42 1
02 1 stroke 78 1
02 2 cancer . 2
02 3 stroke . .
03 1 stroke 66 2
03 2 copd . 1
03 3 . . .
;
run;

proc transpose data=have out=wide2 
	prefix=visit_num;
by id;
var visit_num;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Desired output:&lt;/P&gt;
&lt;TABLE border="1" width="580px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="40px" height="30px"&gt;ID&lt;/TD&gt;
&lt;TD width="92.5167px" height="30px"&gt;Visit_Num1&lt;/TD&gt;
&lt;TD width="92.5167px"&gt;Visit_Num2&lt;/TD&gt;
&lt;TD width="92.5167px"&gt;Visit_Num3&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;Age&lt;/TD&gt;
&lt;TD width="92.25px"&gt;Treatment1&lt;/TD&gt;
&lt;TD width="40px"&gt;Treatment2&lt;/TD&gt;
&lt;TD width="92.25px"&gt;Treatment3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" height="30px"&gt;01&lt;/TD&gt;
&lt;TD width="92.5167px" height="30px"&gt;diabetes&lt;/TD&gt;
&lt;TD width="92.5167px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="92.5167px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;42&lt;/TD&gt;
&lt;TD width="92.25px"&gt;1&lt;/TD&gt;
&lt;TD width="40px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="92.25px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" height="30px"&gt;02&lt;/TD&gt;
&lt;TD width="92.5167px" height="30px"&gt;stroke&lt;/TD&gt;
&lt;TD width="92.5167px"&gt;cancer&lt;/TD&gt;
&lt;TD width="92.5167px"&gt;stroke&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;78&lt;/TD&gt;
&lt;TD width="92.25px"&gt;1&lt;/TD&gt;
&lt;TD width="40px"&gt;2&lt;/TD&gt;
&lt;TD width="92.25px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px"&gt;03&lt;/TD&gt;
&lt;TD width="92.5167px"&gt;stroke&lt;/TD&gt;
&lt;TD width="92.5167px"&gt;copd&lt;/TD&gt;
&lt;TD width="92.5167px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="40px"&gt;66&lt;/TD&gt;
&lt;TD width="92.25px"&gt;2&lt;/TD&gt;
&lt;TD width="40px"&gt;1&lt;/TD&gt;
&lt;TD width="92.25px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Sat, 28 Aug 2021 20:16:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-transpose-to-transform-dataset-from-long-to-wide/m-p/764646#M30497</guid>
      <dc:creator>monsterpie</dc:creator>
      <dc:date>2021-08-28T20:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc transpose to transform dataset from long to wide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-transpose-to-transform-dataset-from-long-to-wide/m-p/764660#M30498</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=wide1
	prefix=visit_num;
by id;
id visit_num;
var diag;
run;

proc transpose data=have out=wide2
	prefix=treatment;
by id;
id visit_num;
var treatment;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then merge the datasets.&lt;/P&gt;
&lt;P&gt;Or do you rather need a report?&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 06:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-transpose-to-transform-dataset-from-long-to-wide/m-p/764660#M30498</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-29T06:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: Proc transpose to transform dataset from long to wide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-transpose-to-transform-dataset-from-long-to-wide/m-p/764666#M30499</link>
      <description>&lt;P&gt;The simplest way is using PROC SUMMARY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input id visit_num diag$ age treatment;
cards;
01 1 diabetes 42 1
02 1 stroke 78 1
02 2 cancer . 2
02 3 stroke . .
03 1 stroke 66 2
03 2 copd . 1
03 3 . . .
;
run;

proc sql noprint;
select max(n) into :n
 from (select count(*) as n from have group by id);
quit;
proc summary data=have;
by id;
output out=want idgroup(out[&amp;amp;n] (visit_num diag age treatment)=);
run;&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 Aug 2021 11:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-transpose-to-transform-dataset-from-long-to-wide/m-p/764666#M30499</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-08-29T11:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: Proc transpose to transform dataset from long to wide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-transpose-to-transform-dataset-from-long-to-wide/m-p/764671#M30501</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; for your response and help. Would you mind just providing me a brief explanation of each line of code? I'd like to ensure I understand it for future reference. Thank you again.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 13:21:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-transpose-to-transform-dataset-from-long-to-wide/m-p/764671#M30501</guid>
      <dc:creator>monsterpie</dc:creator>
      <dc:date>2021-08-29T13:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc transpose to transform dataset from long to wide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-transpose-to-transform-dataset-from-long-to-wide/m-p/764815#M30508</link>
      <description>You should check sas documentation about PROC SUMMARY + IDGROUP option at &lt;BR /&gt;support.sas.com&lt;BR /&gt;.&lt;BR /&gt;You could find all you need in its documentation.</description>
      <pubDate>Mon, 30 Aug 2021 11:51:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-transpose-to-transform-dataset-from-long-to-wide/m-p/764815#M30508</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-08-30T11:51:37Z</dc:date>
    </item>
  </channel>
</rss>

