<?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: Learning SAS...would like some help with an exercise on Proc Transpose in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-would-like-some-help-with-an-exercise-on-Proc/m-p/60056#M17013</link>
    <description>Kyle,&lt;BR /&gt;
&lt;BR /&gt;
I'm not sure if there is any option that can do what you want, but you can always reorder the variables after having run proc transpose.  For example, the following will do just that if run after the statements shown in your example:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
  select strip(name) into :vars separated by ' '&lt;BR /&gt;
    from dictionary.columns&lt;BR /&gt;
      where libname="WORK" and memname="TEST2"&lt;BR /&gt;
        order by 1&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
 &lt;BR /&gt;
data want;&lt;BR /&gt;
  retain &amp;amp;vars.;&lt;BR /&gt;
  set test2;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art</description>
    <pubDate>Fri, 29 Apr 2011 13:46:40 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2011-04-29T13:46:40Z</dc:date>
    <item>
      <title>Learning SAS...would like some help with an exercise on Proc Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-would-like-some-help-with-an-exercise-on-Proc/m-p/60055#M17012</link>
      <description>Hi, just wondering if anyone can provide some help on this SAS exercise I'm working on using Proc Transpose.  Here is my code:&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
input sid score year;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 89 2001&lt;BR /&gt;
2 88 2001&lt;BR /&gt;
1 92 2002&lt;BR /&gt;
2 98 2003&lt;BR /&gt;
1 99 2004&lt;BR /&gt;
2 89 2004&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=test;&lt;BR /&gt;
	by sid;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc transpose data=test out=test2 prefix=year;&lt;BR /&gt;
	var score;&lt;BR /&gt;
	by sid;&lt;BR /&gt;
	id year;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=test2;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Here is the output (looks a little weird in this thread but you get the idea):&lt;BR /&gt;
&lt;BR /&gt;
 Obs    sid    _NAME_    year2001    year2002    year2004    year2003&lt;BR /&gt;
&lt;BR /&gt;
    1      1        score          89                   92          99              .&lt;BR /&gt;
    2      2        score          88                     .          89             98&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
in the output, the values for variable year would become variables themselves but year2004 is before year2003.  How do I put year2003 before year2004.  What modifications do I need to make to my code in order to do this?  &lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Fri, 29 Apr 2011 13:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-would-like-some-help-with-an-exercise-on-Proc/m-p/60055#M17012</guid>
      <dc:creator>KyleS83</dc:creator>
      <dc:date>2011-04-29T13:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Learning SAS...would like some help with an exercise on Proc Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-would-like-some-help-with-an-exercise-on-Proc/m-p/60056#M17013</link>
      <description>Kyle,&lt;BR /&gt;
&lt;BR /&gt;
I'm not sure if there is any option that can do what you want, but you can always reorder the variables after having run proc transpose.  For example, the following will do just that if run after the statements shown in your example:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
  select strip(name) into :vars separated by ' '&lt;BR /&gt;
    from dictionary.columns&lt;BR /&gt;
      where libname="WORK" and memname="TEST2"&lt;BR /&gt;
        order by 1&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
 &lt;BR /&gt;
data want;&lt;BR /&gt;
  retain &amp;amp;vars.;&lt;BR /&gt;
  set test2;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art</description>
      <pubDate>Fri, 29 Apr 2011 13:46:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-would-like-some-help-with-an-exercise-on-Proc/m-p/60056#M17013</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-04-29T13:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: Learning SAS...would like some help with an exercise on Proc Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-would-like-some-help-with-an-exercise-on-Proc/m-p/60057#M17014</link>
      <description>Hello KyleS83,&lt;BR /&gt;
&lt;BR /&gt;
In you case the simpliest way is to add one more datastep:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data test2;&lt;BR /&gt;
  retain sid _NAME_ year2001-year2004;&lt;BR /&gt;
  set test2;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Fri, 29 Apr 2011 13:52:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-would-like-some-help-with-an-exercise-on-Proc/m-p/60057#M17014</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-04-29T13:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: Learning SAS...would like some help with an exercise on Proc Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-would-like-some-help-with-an-exercise-on-Proc/m-p/60058#M17015</link>
      <description>[pre]&lt;BR /&gt;
data test;&lt;BR /&gt;
input sid score year;&lt;BR /&gt;
cards;&lt;BR /&gt;
1 89 2001&lt;BR /&gt;
2 88 2001&lt;BR /&gt;
1 92 2002&lt;BR /&gt;
2 98 2003&lt;BR /&gt;
1 99 2004&lt;BR /&gt;
2 89 2004&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql  ;&lt;BR /&gt;
create table temp as&lt;BR /&gt;
 select *&lt;BR /&gt;
  from (select distinct sid from test),(select distinct year from test)&lt;BR /&gt;
  ;&lt;BR /&gt;
&lt;BR /&gt;
create table op as &lt;BR /&gt;
 select temp.*,score&lt;BR /&gt;
  from temp left join test on temp.sid = test.sid and temp.year = test.year&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
proc transpose data=op out=want prefix=year;&lt;BR /&gt;
 by sid;&lt;BR /&gt;
 id year;&lt;BR /&gt;
 var score;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Tue, 03 May 2011 04:54:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Learning-SAS-would-like-some-help-with-an-exercise-on-Proc/m-p/60058#M17015</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-03T04:54:24Z</dc:date>
    </item>
  </channel>
</rss>

