<?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: transpose data without proc transpose in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-without-proc-transpose/m-p/450774#M113548</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;:&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175025"&gt;@rvsidhu035&lt;/a&gt;&amp;nbsp;already has accepted a solution but, of course, I agree with you. In this case I, personally, would use the macro after running proc transpose to make the dataset long. i.e.:&lt;/P&gt;
&lt;PRE&gt;data new30;
  input id $ sysbp diabp;
cards;
001 130 80
002 110 90
003 140 70
004 120 80
005 130 70
;
run;

proc transpose data=new30 out=need;
  var sysbp diabp;
  by id;
run;

%transpose(data=need, out=want, by=_name_, id=id, 
 prefix=_, var=col1, use_varname=no, sort=yes)
&lt;/PRE&gt;
&lt;P&gt;Requires a lot less code, has a lot less chance of making an error, and should take a lot less time than all of those steps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Apr 2018 18:12:41 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2018-04-03T18:12:41Z</dc:date>
    <item>
      <title>transpose data without proc transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-without-proc-transpose/m-p/450544#M113436</link>
      <description>&lt;P&gt;data new30;&lt;BR /&gt;Input id $ sysbp diabp;&lt;BR /&gt;Cards;&lt;BR /&gt;001 130 80&lt;BR /&gt;002 110 90&lt;BR /&gt;003 140 70&lt;BR /&gt;004 120 80&lt;BR /&gt;005 130 70&lt;BR /&gt;;&lt;BR /&gt;Transpose the above dataset without using proc transpose.&lt;BR /&gt;_name_ 001 002 003 004 005&lt;BR /&gt;Sysbp 130 110 140 120 130&lt;BR /&gt;Diabp 80 90 70 80 70&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 08:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-without-proc-transpose/m-p/450544#M113436</guid>
      <dc:creator>rvsidhu035</dc:creator>
      <dc:date>2018-04-03T08:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data without proc transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-without-proc-transpose/m-p/450547#M113437</link>
      <description>&lt;P&gt;There is &lt;A href="http://www.sascommunity.org/wiki/A_Better_Way_to_Flip_(Transpose)_a_SAS_Dataset" target="_self"&gt;A Better Way to Flip&lt;/A&gt;&amp;nbsp;than PROC TRANSPOSE &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 08:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-without-proc-transpose/m-p/450547#M113437</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-04-03T08:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data without proc transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-without-proc-transpose/m-p/450548#M113438</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175025"&gt;@rvsidhu035&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;Transpose the above dataset without using proc transpose.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;"Walk, but don't use your legs". Somebody mislaid their brain.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW 001 002 003 004 005 are not valid SAS names, so that's idiocy #2.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 09:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-without-proc-transpose/m-p/450548#M113438</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-03T09:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data without proc transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-without-proc-transpose/m-p/450550#M113439</link>
      <description>&lt;P&gt;And why do you not want to use proc transpose - given that the proc transpose was built, tested, and specifically optimised for such a procedure this does not make any sense?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do not use the procedure designed for such a task then you need to have a few extra steps, and you need to make assumptions about your data.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data new30;
  input id $ sysbp diabp;
cards;
001 130 80
002 110 90
003 140 70
004 120 80
005 130 70
;
run;

proc sql noprint;
  select distinct cats("_",id) into :tot separated by " " from new30;
quit;

data want1 (keep=_name_ _:);
  set new30 end=last;
  array dat &amp;amp;tot.;
  retain _:;
  _name_="sysbp";
  do i=1 to dim(dat);
    if cats("_",id)=vname(dat{i}) then dat{i}=sysbp;
  end;
  if last then output;
run;
  
data want2 (keep=_name_ _:);
  set new30 end=last;
  array dat &amp;amp;tot.;
  retain _:;
  _name_="diabp";
  do i=1 to dim(dat);
    if cats("_",id)=vname(dat{i}) then dat{i}=diabp;
  end;
  if last then output;
run;

data want;
  set want1 want2;
run;&lt;/PRE&gt;
&lt;P&gt;And then of course once you have created the code, you can start to condense it:&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
  select distinct cats("_",id) into :tot separated by " " from new30;
quit;

%macro tran (type=,id=);
  data want&amp;amp;id. (keep=_name_ _:);
    set new30 end=last;
    array dat &amp;amp;tot.;
    retain _:;
    _name_="&amp;amp;type.";
    do i=1 to dim(dat);
      if cats("_",id)=vname(dat{i}) then dat{i}=&amp;amp;type.;
    end;
    if last then output;
  run;
%mend tran;

%tran (type=sysbp,id=1);
%tran (type=diabp,id=2);

data want;
  set want1 want2;
run;
  &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 09:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-without-proc-transpose/m-p/450550#M113439</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-04-03T09:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data without proc transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-without-proc-transpose/m-p/450589#M113459</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new30;
Input id $ sysbp diabp;
Cards;
001 130 80
002 110 90
003 140 70
004 120 80
005 130 70
;
data have;
 set new30;
 _name_='sysbp';value=sysbp;output;
 _name_='diabp';value=diabp;output;
 keep id _name_ value;
run;
proc freq data=new30 noprint;
table id/out=id nopercent;
run;
data _null_;
 set id end=last;
 if _n_=1 then call execute('data want;merge ');
 call execute(catt('have(where=(id="',id,'") rename=(value=_',id,'))'));
 if last then call execute(';drop id;run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Apr 2018 12:23:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-without-proc-transpose/m-p/450589#M113459</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-04-03T12:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data without proc transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-without-proc-transpose/m-p/450721#M113522</link>
      <description>&lt;P&gt;call excute?&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 15:53:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-without-proc-transpose/m-p/450721#M113522</guid>
      <dc:creator>rvsidhu035</dc:creator>
      <dc:date>2018-04-03T15:53:58Z</dc:date>
    </item>
    <item>
      <title>Re: transpose data without proc transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/transpose-data-without-proc-transpose/m-p/450774#M113548</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;:&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/175025"&gt;@rvsidhu035&lt;/a&gt;&amp;nbsp;already has accepted a solution but, of course, I agree with you. In this case I, personally, would use the macro after running proc transpose to make the dataset long. i.e.:&lt;/P&gt;
&lt;PRE&gt;data new30;
  input id $ sysbp diabp;
cards;
001 130 80
002 110 90
003 140 70
004 120 80
005 130 70
;
run;

proc transpose data=new30 out=need;
  var sysbp diabp;
  by id;
run;

%transpose(data=need, out=want, by=_name_, id=id, 
 prefix=_, var=col1, use_varname=no, sort=yes)
&lt;/PRE&gt;
&lt;P&gt;Requires a lot less code, has a lot less chance of making an error, and should take a lot less time than all of those steps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 18:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/transpose-data-without-proc-transpose/m-p/450774#M113548</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-04-03T18:12:41Z</dc:date>
    </item>
  </channel>
</rss>

