<?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: how to put the latest date as the first in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-to-put-the-latest-date-as-the-first/m-p/306671#M61037</link>
    <description>&lt;P&gt;I just added a new piece of code to clarify my problem, sorry for confusing you.&lt;/P&gt;</description>
    <pubDate>Mon, 24 Oct 2016 00:01:55 GMT</pubDate>
    <dc:creator>zhangda</dc:creator>
    <dc:date>2016-10-24T00:01:55Z</dc:date>
    <item>
      <title>how to put the latest date as the first</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-put-the-latest-date-as-the-first/m-p/306652#M61035</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to rearrange the year column as you see below, in the order as the lastest date as first, for instance, Q3_2016, Q2_2016, Q1_2016, Q4_2015, Q3_2015, Q2_2015. One thing is that, the quarter keeps rolling, that means, when we are at the beginning of 2017, I will have Q4_2016 rolled into the dataset. &amp;nbsp;then how to make it? Thanks a lot!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data old;&lt;BR /&gt;input year $ resp ;&lt;BR /&gt;datalines;&lt;BR /&gt;Q1_2015 0.35&lt;BR /&gt;Q2_2015 0.55&lt;BR /&gt;Q3_2015 0.65&lt;BR /&gt;Q4_2015 0.75&lt;BR /&gt;Q1_2016 0.47&lt;BR /&gt;Q2_2016 0.58&lt;BR /&gt;Q3_2016 0.69&lt;BR /&gt;;run;&lt;/P&gt;&lt;P&gt;proc transpose data=old out=new;&lt;BR /&gt;id year;&lt;BR /&gt;var resp ;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2016 00:01:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-put-the-latest-date-as-the-first/m-p/306652#M61035</guid>
      <dc:creator>zhangda</dc:creator>
      <dc:date>2016-10-24T00:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to put the latest date as the first</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-put-the-latest-date-as-the-first/m-p/306668#M61036</link>
      <description>&lt;P&gt;You talk about columns but show rows of data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How exactly do you want your output to be?&lt;/P&gt;</description>
      <pubDate>Sun, 23 Oct 2016 22:52:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-put-the-latest-date-as-the-first/m-p/306668#M61036</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-23T22:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to put the latest date as the first</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-put-the-latest-date-as-the-first/m-p/306671#M61037</link>
      <description>&lt;P&gt;I just added a new piece of code to clarify my problem, sorry for confusing you.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2016 00:01:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-put-the-latest-date-as-the-first/m-p/306671#M61037</guid>
      <dc:creator>zhangda</dc:creator>
      <dc:date>2016-10-24T00:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to put the latest date as the first</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-put-the-latest-date-as-the-first/m-p/306674#M61038</link>
      <description>&lt;P&gt;You need to use a variable which sorts the way you want it in your ID statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your YEAR variable is character and therefore all Q1... values will be before Q2...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below an approach which should give you what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data old;
  input year $ resp;
  datalines;
Q1_2015 0.35
Q2_2015 0.55
Q3_2015 0.65
Q4_2015 0.75
Q1_2016 0.47
Q2_2016 0.58
Q3_2016 0.69
;
run;

data need(drop=fmtname start label) cntlin(keep=fmtname start label);
  set old;
  format dt yyq6.;
  dt=input(substr(year,4,4)||substr(year,1,2),yyq6.);
  
  retain fmtname 'myQuarters';
  start=dt;
  label=year;
run;

proc format cntlin=cntlin;
run;

proc transpose data=need out=new;
  id dt;
  format dt myQuarters.;
  var resp;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Oct 2016 02:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-put-the-latest-date-as-the-first/m-p/306674#M61038</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-10-24T02:03:00Z</dc:date>
    </item>
  </channel>
</rss>

