<?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 for all variables except one in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830119#M81991</link>
    <description>&lt;P&gt;Besides being hard to work with your expected output, placing character and what were numeric values into a single variable means that the numeric have to be converted to text which can lead to some issues depending on the actual values, especially if decimals and the actual needed result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The desired output for multiple values of the same PID also means that Transpose isn't the tool as it would create value2 value3, etc, for each repetition of PID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ugly but does what is requested:&lt;/P&gt;
&lt;PRE&gt;data demo;
input pid $ siteid $ subjid $ age sex $ race $;
cards;
101 001 010 23 M asian
101 002 011 21 M cauca
102 003 011 34 F white
101 001 010 11 F black
;
run; 

data want;
   set demo;
   length parameter $ 10 value $ 5;
   Parameter='siteid';
   value=siteid;
   output;
   Parameter='subjid';
   value=subjid;
   output;
   Parameter='age';
   value=put(age,f2. -L);
   output;
   Parameter='sex';
   value=sex;
   output;
   Parameter='race';
   value=race;
   output;
   keep pid parameter value;
run;
&lt;/PRE&gt;</description>
    <pubDate>Wed, 24 Aug 2022 15:52:28 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-08-24T15:52:28Z</dc:date>
    <item>
      <title>proc transpose for all variables except one</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830105#M81986</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I need to transpose almost 50 variables using proc transpose for which I kept statement (Var=_all_)&lt;/P&gt;
&lt;P&gt;which is not working as per my expectation. It is because one variable PID from below data is repeated everytimes. can you please help&lt;/P&gt;
&lt;P&gt;&lt;U&gt;My expected output&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;pid&amp;nbsp; &amp;nbsp;parameter&amp;nbsp; &amp;nbsp;value&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; siteid&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 001&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp;subjid&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 010&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; age&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; sex&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; race&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;asian&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; siteid&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 002&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp;subjid&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 011&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; age&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; sex&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; race&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cauca&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data demo;
input pid $ siteid $ subjid $ age sex $ race $;
cards;
101 001 010 23 M asian
101 002 011 21 M cauca
102 003 011 34 F white
101 001 010 11 F black
;
run; 

proc sort data=demo out=demo1; by pid;run;
proc transpose data=demo1 out=demo2 (RENAME=(_NAME_=PARAMETER COL1=VALUE));
by pid;
var &lt;STRONG&gt;_all_&lt;/STRONG&gt; ;
run;&lt;/PRE&gt;
&lt;P&gt;Also I am getting note as&lt;/P&gt;
&lt;P&gt;NOTE: Numeric variables in the input data set will be converted to character in the output data set.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 15:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830105#M81986</guid>
      <dc:creator>abraham1</dc:creator>
      <dc:date>2022-08-24T15:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose for all variables except one</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830108#M81987</link>
      <description>&lt;P&gt;I would not bother transposing the data set named DEMO. What is the benefit here of doing such a transpose? What can you do with the transposed result better than with the un-transposed result? Please explain how you would use the transposed data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 15:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830108#M81987</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-24T15:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose for all variables except one</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830110#M81988</link>
      <description>I want to display all parameters (variable) values in vertical format for analysis in a clinical trial based on unique PID.&lt;BR /&gt;</description>
      <pubDate>Wed, 24 Aug 2022 15:39:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830110#M81988</guid>
      <dc:creator>abraham1</dc:creator>
      <dc:date>2022-08-24T15:39:17Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose for all variables except one</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830111#M81989</link>
      <description>&lt;P&gt;Like that?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
input pid $ siteid $ subjid $ age sex $ race $;
cards;
101 001 010 23 M asian
101 002 011 21 M cauca
102 003 011 34 F white
101 001 010 11 F black
;
run; 

data demo;
set demo;
_x_+1;
run;

proc sort data=demo out=demo1; 
by _x_ pid siteid;
run;

proc print data = demo1  ;
run;

proc transpose data=demo1(drop=pid) out=demo2 (RENAME=(_NAME_=PARAMETER COL1=VALUE)
where=(PARAMETER ne "_x_") drop=_x_);
by _x_ ;
var _all_ ;
run;

proc print data = demo2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 15:41:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830111#M81989</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-08-24T15:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose for all variables except one</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830113#M81990</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/357256"&gt;@abraham1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I want to display all parameters (variable) values in vertical format for analysis in a clinical trial based on unique PID.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, I see that. Why? What is the benefit?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 15:42:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830113#M81990</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-24T15:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose for all variables except one</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830119#M81991</link>
      <description>&lt;P&gt;Besides being hard to work with your expected output, placing character and what were numeric values into a single variable means that the numeric have to be converted to text which can lead to some issues depending on the actual values, especially if decimals and the actual needed result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The desired output for multiple values of the same PID also means that Transpose isn't the tool as it would create value2 value3, etc, for each repetition of PID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ugly but does what is requested:&lt;/P&gt;
&lt;PRE&gt;data demo;
input pid $ siteid $ subjid $ age sex $ race $;
cards;
101 001 010 23 M asian
101 002 011 21 M cauca
102 003 011 34 F white
101 001 010 11 F black
;
run; 

data want;
   set demo;
   length parameter $ 10 value $ 5;
   Parameter='siteid';
   value=siteid;
   output;
   Parameter='subjid';
   value=subjid;
   output;
   Parameter='age';
   value=put(age,f2. -L);
   output;
   Parameter='sex';
   value=sex;
   output;
   Parameter='race';
   value=race;
   output;
   keep pid parameter value;
run;
&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Aug 2022 15:52:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830119#M81991</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-08-24T15:52:28Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose for all variables except one</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830159#M81992</link>
      <description>&lt;P&gt;The solution is working fine. Is it possible to add the PID column in the beginning so that each variable value will be populated like below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;pid&amp;nbsp; &amp;nbsp;parameter&amp;nbsp; &amp;nbsp;value&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; siteid&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 001&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp;subjid&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 010&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; age&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; sex&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M&lt;/P&gt;
&lt;P&gt;101&amp;nbsp; &amp;nbsp; race&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;asian&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 17:12:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830159#M81992</guid>
      <dc:creator>abraham1</dc:creator>
      <dc:date>2022-08-24T17:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose for all variables except one</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830164#M81993</link>
      <description>&lt;P&gt;remove:&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;(drop=pid)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Aug 2022 17:39:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830164#M81993</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-08-24T17:39:51Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose for all variables except one</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830167#M81994</link>
      <description>&lt;P&gt;If you do not have a set of key variables to use for the BY statement of PROC TRANSPOSE then you need to add another variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
input pid $ siteid $ subjid $ age sex $ race $;
cards;
101 001 010 23 M asian
101 002 011 21 M cauca
102 003 011 34 F white
101 001 010 11 F black
;

data step1;
  row+1;
  set demo;
run;

proc transpose data=step1 out=want(rename=(_name_=PARAM col1=VALUE)) ;
  by row pid ;
  var _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs    row    pid    PARAM        VALUE

  1     1     101    row                  1
  2     1     101    pid       101
  3     1     101    siteid    001
  4     1     101    subjid    010
  5     1     101    age                 23
  6     1     101    sex       M
  7     1     101    race      asian
  8     2     101    row                  2
  9     2     101    pid       101
 10     2     101    siteid    002
 11     2     101    subjid    011
 12     2     101    age                 21
 13     2     101    sex       M
 14     2     101    race      cauca
 15     3     102    row                  3
 16     3     102    pid       102
 17     3     102    siteid    003
 18     3     102    subjid    011
 19     3     102    age                 34
 20     3     102    sex       F
 21     3     102    race      white
 22     4     101    row                  4
 23     4     101    pid       101
 24     4     101    siteid    001
 25     4     101    subjid    010
 26     4     101    age                 11
 27     4     101    sex       F
 28     4     101    race      black

&lt;/PRE&gt;
&lt;P&gt;You can add a WHERE= dataset option on the output dataset to exclude the observations for the BY variables.&amp;nbsp; Or add a post processing step to remove those observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also noticed how the numeric values are right aligned.&amp;nbsp; You could either add a post processing step to remove the leading spaces.&amp;nbsp; Or transpose the numeric and character variables separately and create two value columns, one for the numeric values and one for the character values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data final;
  set want;
  if upcase(param) in ('PID' 'ROW') then delete;
  value = left(value);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Aug 2022 18:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-transpose-for-all-variables-except-one/m-p/830167#M81994</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-24T18:02:36Z</dc:date>
    </item>
  </channel>
</rss>

