<?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 force column names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-Transpose-force-column-names/m-p/783457#M249806</link>
    <description>&lt;P&gt;Explain further. Show us what the desired output is. In particular, how are the values of variable z derived?&lt;/P&gt;</description>
    <pubDate>Wed, 01 Dec 2021 20:03:22 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-12-01T20:03:22Z</dc:date>
    <item>
      <title>PROC Transpose force column names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-Transpose-force-column-names/m-p/783455#M249805</link>
      <description>&lt;P&gt;I have a dataset with these values. I expect values for val as "Z" in future. But currently i have values for x/y.&lt;/P&gt;&lt;P&gt;ID Val&lt;/P&gt;&lt;P&gt;1 x&lt;/P&gt;&lt;P&gt;2 x&lt;/P&gt;&lt;P&gt;3 x&lt;/P&gt;&lt;P&gt;4 y&lt;/P&gt;&lt;P&gt;5 y&lt;/P&gt;&lt;P&gt;6 y&lt;/P&gt;&lt;P&gt;when i transpose it using proc transpose, i get the column names as ID ,[x],[y]&lt;/P&gt;&lt;P&gt;Is there any way i can force the&amp;nbsp; column names as&amp;nbsp;ID ,[x],[y],[z] ??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 19:46:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-Transpose-force-column-names/m-p/783455#M249805</guid>
      <dc:creator>CSK_ROCKS</dc:creator>
      <dc:date>2021-12-01T19:46:11Z</dc:date>
    </item>
    <item>
      <title>Re: PROC Transpose force column names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-Transpose-force-column-names/m-p/783457#M249806</link>
      <description>&lt;P&gt;Explain further. Show us what the desired output is. In particular, how are the values of variable z derived?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 20:03:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-Transpose-force-column-names/m-p/783457#M249806</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-01T20:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: PROC Transpose force column names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-Transpose-force-column-names/m-p/783461#M249810</link>
      <description>&lt;P&gt;You example does not look very useful. Let's make another.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input row column name $ value ;
cards;
1 1 X 100
1 2 Y 200
2 1 X 300
2 2 Y 400
3 1 Y 500
4 1 X 600
;
proc transpose data=have out=want(drop=_name_);
  by row;
  id name;
  var value;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you get the results:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Obs    row     X      Y

 1      1     100    200
 2      2     300    400
 3      3       .    500
 4      4     600      .
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could force the extra variables in a separate step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fixed;
  length row x y z 8;
  set want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could introduce an extra set of observations into the input data fed to PROC TRANSPOSE. (note this step could be a VIEW instead of physical copy of the data).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data for_transpose;
   set have;
   if _n_=1 then do name='X','Y','Z';
       row=.;
       output;
   end;
  set have;
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then drop that ROW=. observation on the output.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=for_transpose out=want(drop=_name_ where=(not missing(row)));
  by row;
  id name;
  var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Dec 2021 20:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-Transpose-force-column-names/m-p/783461#M249810</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-01T20:46:38Z</dc:date>
    </item>
  </channel>
</rss>

