<?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 How do I transpose my data from long to wide? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-transpose-my-data-from-long-to-wide/m-p/454979#M70004</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having trouble transposing this long data set (see attachment) into a wide one.&lt;/P&gt;&lt;P&gt;I'd like for each row to correlate with a subject and for the blood results to go horizontally (wide) rather than vertically (long) as it stands presently.&lt;/P&gt;&lt;P&gt;Appreciate any help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached excel spreadsheet is a sample of the data I am dealing with and shows how I would like the data transposed but unsure how to go about this with the PROC transpose command. I am using SAS 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;E.G.&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC TRANSPOSE DATA=bloods2 OUT=bloodswide prefix=labvalue;&lt;BR /&gt;BY SUBJECT;&lt;BR /&gt;ID labname;&lt;BR /&gt;VAR labvalue;&lt;BR /&gt;RUN ;&lt;/P&gt;&lt;P&gt;==&amp;gt;&amp;nbsp; lots of error comes up in the log 'ERROR: The ID value "labvalue_Ery__Mean_Cell_Hemoglob" occurs twice in the same BY group.'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;</description>
    <pubDate>Wed, 18 Apr 2018 00:59:01 GMT</pubDate>
    <dc:creator>lavienrose1</dc:creator>
    <dc:date>2018-04-18T00:59:01Z</dc:date>
    <item>
      <title>How do I transpose my data from long to wide?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-transpose-my-data-from-long-to-wide/m-p/454979#M70004</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having trouble transposing this long data set (see attachment) into a wide one.&lt;/P&gt;&lt;P&gt;I'd like for each row to correlate with a subject and for the blood results to go horizontally (wide) rather than vertically (long) as it stands presently.&lt;/P&gt;&lt;P&gt;Appreciate any help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached excel spreadsheet is a sample of the data I am dealing with and shows how I would like the data transposed but unsure how to go about this with the PROC transpose command. I am using SAS 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;E.G.&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC TRANSPOSE DATA=bloods2 OUT=bloodswide prefix=labvalue;&lt;BR /&gt;BY SUBJECT;&lt;BR /&gt;ID labname;&lt;BR /&gt;VAR labvalue;&lt;BR /&gt;RUN ;&lt;/P&gt;&lt;P&gt;==&amp;gt;&amp;nbsp; lots of error comes up in the log 'ERROR: The ID value "labvalue_Ery__Mean_Cell_Hemoglob" occurs twice in the same BY group.'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 00:59:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-transpose-my-data-from-long-to-wide/m-p/454979#M70004</guid>
      <dc:creator>lavienrose1</dc:creator>
      <dc:date>2018-04-18T00:59:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I transpose my data from long to wide?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-transpose-my-data-from-long-to-wide/m-p/454983#M70005</link>
      <description>&lt;P&gt;You need to sort the data by the by variables you have before transposing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SORT DATA=&lt;SPAN&gt;bloods2;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;BY&amp;nbsp;SUBJECT;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;PROC TRANSPOSE DATA=bloods2 OUT=bloodswide prefix=labvalue;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;BY SUBJECT;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ID labname;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;VAR labvalue;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RUN ;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 01:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-transpose-my-data-from-long-to-wide/m-p/454983#M70005</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-04-18T01:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I transpose my data from long to wide?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-transpose-my-data-from-long-to-wide/m-p/455001#M70006</link>
      <description>&lt;P&gt;When you transpose, your labnames will be truncated or will throw an error because they will not meet the SAS Variable name rules. So use VALIDVARNAMES option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=v7;
PROC SORT DATA=bloods;
by subject sample_dt;
proc transpose data=bloods out=need prefix=Var_;
by subject sample_dt;
var labvalue;
label var_1="testing";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want your names as it is in your reports then you can have them as labels.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table dummy_var as 
select labname, CAT("var_",monotonic()) as dummy
from (select distinct labname from bloods);
quit;
proc sql;
select strip(dummy)||"='"||strip(labname)||"'" INTO: Label_List separated by " " 
from dummy_var;
quit;
proc sql;
create table have as 
select t1.*,t2.dummy
from bloods t1
left join dummy_var t2 on t1.labname=t2.labname;
quit;

PROC SORT DATA=have;
by subject sample_dt;
proc transpose data=have out=want(drop=_NAME_) ;
by subject sample_dt;
var labvalue;
ID dummy;
run;

DATA Want;
SET WANT;
LABEL &amp;amp;Label_List;
run;
proc print data=want label;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Apr 2018 02:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-transpose-my-data-from-long-to-wide/m-p/455001#M70006</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-04-18T02:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I transpose my data from long to wide?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-do-I-transpose-my-data-from-long-to-wide/m-p/455015#M70007</link>
      <description>&lt;P&gt;Thanks very much SuryaKiran - that was extremely helpful&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 03:18:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-do-I-transpose-my-data-from-long-to-wide/m-p/455015#M70007</guid>
      <dc:creator>lavienrose1</dc:creator>
      <dc:date>2018-04-18T03:18:37Z</dc:date>
    </item>
  </channel>
</rss>

