<?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-order of columns of ID varaible in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-order-of-columns-of-ID-varaible/m-p/560366#M156677</link>
    <description>&lt;P&gt;The order of columns in a dataset is irrelevant, as columns are addressed by names.&lt;/P&gt;
&lt;P&gt;Transpose adds the new columns whenever the first instance is encountered.&lt;/P&gt;
&lt;P&gt;If you need a special order for display (eg in a report), you can prepare the order dynamically:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aaa;
input ID month sum_loan;
cards;
1 1901 10
1 1902 20
1 1904 30
2 1901 40
2 1903 50
;

proc transpose data=aaa name=metric prefix=YYMM_ out=bbb;
id month;
by ID;
var sum_loan;
run;

proc sql noprint;
select name into :names separated by ' '
from dictionary.columns
where libname = 'WORK' and memname = 'BBB' and name like 'YYMM%'
order by name;
quit;

proc print data=bbb noobs;
var id &amp;amp;names.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 21 May 2019 06:52:00 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-05-21T06:52:00Z</dc:date>
    <item>
      <title>proc transpose-order of columns of ID varaible</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-order-of-columns-of-ID-varaible/m-p/560353#M156673</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I am using proc transpose.&lt;/P&gt;
&lt;P&gt;In the result&amp;nbsp; the order of columns&amp;nbsp; is :YYMM_1901, YYMM_1902, YYMM_1904, YYMM_1903.&lt;/P&gt;
&lt;P&gt;But I want to have order : YYMM_1901, YYMM_1902, YYMM_1903, YYMM_1904.&lt;/P&gt;
&lt;P&gt;What is the way to control the order of the columns?&lt;/P&gt;
&lt;P&gt;I know that I can use retain statement in a separate data step.&lt;/P&gt;
&lt;P&gt;Is there a way to control columns order within proc transpose?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data aaa;
input ID  month sum_loan;
cards;
1 1901 10
1 1902 20
1 1904 30
2 1901 40
2 1903 50
;
run;
proc transpose data=aaa name=Metric prefix=YYMM_ out=bbb;
id month;
by ID ;
var sum_loan;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 May 2019 05:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-order-of-columns-of-ID-varaible/m-p/560353#M156673</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-05-21T05:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose-order of columns of ID varaible</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-order-of-columns-of-ID-varaible/m-p/560366#M156677</link>
      <description>&lt;P&gt;The order of columns in a dataset is irrelevant, as columns are addressed by names.&lt;/P&gt;
&lt;P&gt;Transpose adds the new columns whenever the first instance is encountered.&lt;/P&gt;
&lt;P&gt;If you need a special order for display (eg in a report), you can prepare the order dynamically:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data aaa;
input ID month sum_loan;
cards;
1 1901 10
1 1902 20
1 1904 30
2 1901 40
2 1903 50
;

proc transpose data=aaa name=metric prefix=YYMM_ out=bbb;
id month;
by ID;
var sum_loan;
run;

proc sql noprint;
select name into :names separated by ' '
from dictionary.columns
where libname = 'WORK' and memname = 'BBB' and name like 'YYMM%'
order by name;
quit;

proc print data=bbb noobs;
var id &amp;amp;names.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 May 2019 06:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-order-of-columns-of-ID-varaible/m-p/560366#M156677</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-05-21T06:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: proc transpose-order of columns of ID varaible</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-transpose-order-of-columns-of-ID-varaible/m-p/560472#M156735</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data aaa;
input ID  month sum_loan;
cards;
1 1901 10
1 1902 20
1 1904 30
2 1901 40
2 1903 50
;
run;
proc transpose data=aaa name=Metric prefix=YYMM_ out=bbb;
id month;
by ID ;
var sum_loan;
run;


proc transpose data=bbb(obs=0) out=temp;
var yymm_:;
run;
proc sql noprint;
select _NAME_ into : names separated by ' '
 from temp
  order by input(scan(_NAME_,-1,'_'),best.);
run;
data want;
 retain id metric &amp;amp;names;
 set bbb;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 May 2019 12:51:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-transpose-order-of-columns-of-ID-varaible/m-p/560472#M156735</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-05-21T12:51:09Z</dc:date>
    </item>
  </channel>
</rss>

