<?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: long to wide in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237869#M14810</link>
    <description>There's no attachment, and I'm not a fan of downloading files.  &lt;BR /&gt;</description>
    <pubDate>Fri, 04 Dec 2015 17:46:46 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2015-12-04T17:46:46Z</dc:date>
    <item>
      <title>long to wide</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237858#M14806</link>
      <description>data gamdist; input cust_xref_id 1-6 Fico 9-12 rsn_cd1 13-15 rsn_cd2 17-19 Yr_Month $21-28; cards; 15013 668 39 18 2014-01 15013 668 39 18 2014-02 15013 668 39 18 2014-03 15013 670 39 18 2014-04 15013 678 39 18 2014-05 15013 638 38 20 2014-07 15013 635 38 20 2014-08 15013 635 38 20 2014-09 15013 643 38 20 2014-10 15013 643 38 20 2014-11 15013 648 38 24 2014-12 15013 648 38 24 2015-01 15013 648 38 24 2015-02 15013 651 38 24 2015-04 15013 653 38 24 2015-05 15013 653 38 24 2015-07 15013 654 38 24 2015-08 15013 661 38 24 2015-09 15013 662 38 24 2015-10 15013 662 38 24 2015-11 ; run; how to convert the above data to single record from minimum yr_month to maximum as below cust_xref_id fico_2014_01 rsn_cd1_2014_01 rsn_cd2_2014_01 fico_2014_02 rsn_cd1_2014_02 rsn_cd2_2014_02 ..........so on .....</description>
      <pubDate>Fri, 04 Dec 2015 17:06:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237858#M14806</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2015-12-04T17:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: long to wide</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237860#M14807</link>
      <description>Please Please, format your code. &lt;BR /&gt;Use the little notepad Icon at the top of the window to enter code.</description>
      <pubDate>Fri, 04 Dec 2015 17:12:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237860#M14807</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-04T17:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: long to wide</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237866#M14809</link>
      <description>Added attachment for the same</description>
      <pubDate>Fri, 04 Dec 2015 17:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237866#M14809</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2015-12-04T17:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: long to wide</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237869#M14810</link>
      <description>There's no attachment, and I'm not a fan of downloading files.  &lt;BR /&gt;</description>
      <pubDate>Fri, 04 Dec 2015 17:46:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237869#M14810</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-04T17:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: long to wide</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237871#M14811</link>
      <description>&lt;P&gt;use 3 proc transpose with statement id year and option prefix=&amp;lt;varname_&amp;gt;. Then merge the 3 together by cust num.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 18:18:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237871#M14811</guid>
      <dc:creator>ndp</dc:creator>
      <dc:date>2015-12-04T18:18:15Z</dc:date>
    </item>
    <item>
      <title>Re: long to wide</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237872#M14812</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data gamdist;
input cust_xref_id 1-6	Fico 9-12	rsn_cd1 13-15	rsn_cd2	17-19 Yr_Month $21-28;
cards;
15013	668	39	18	2014-01
15013	668	39	18	2014-02
15013	668	39	18	2014-03
15013	670	39	18	2014-04
15013	678	39	18	2014-05
15013	638	38	20	2014-07
15013	635	38	20	2014-08
15013	635	38	20	2014-09
15013	643	38	20	2014-10
15013	643	38	20	2014-11
15013	648	38	24	2014-12
15013	648	38	24	2015-01
15013	648	38	24	2015-02
15013	651	38	24	2015-04
15013	653	38	24	2015-05
15013	653	38	24	2015-07
15013	654	38	24	2015-08
15013	661	38	24	2015-09
15013	662	38	24	2015-10
15013	662	38	24	2015-11
;
run;


how to convert the above data to single record from minimum yr_month to maximum as below 

cust_xref_id fico_2014_01 rsn_cd1_2014_01 rsn_cd2_2014_01 fico_2014_02 rsn_cd1_2014_02 rsn_cd2_2014_02 ..........so on .....&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Dec 2015 18:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237872#M14812</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2015-12-04T18:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: long to wide</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237881#M14813</link>
      <description>&lt;P&gt;This implements contributor &lt;STRONG&gt;ndp's&lt;/STRONG&gt; suggestion. It also handles reordering of columns to the way&amp;nbsp;you want them to appear.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Beware that the variables created by PROC TRANSPOSE, regrettably have a hyphen in them:&amp;nbsp;&lt;STRONG&gt;&lt;FONT face="lucida sans unicode,lucida sans"&gt;Fico_2014&lt;FONT color="#FF0000"&gt;-&lt;/FONT&gt;01, rsn_cd1_2014&lt;FONT color="#FF0000"&gt;-&lt;/FONT&gt;01, rsn_cd2_2014&lt;FONT color="#FF0000"&gt;-&lt;/FONT&gt;01&lt;/FONT&gt;&lt;/STRONG&gt;, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Enjoy!&amp;nbsp;&lt;img id="robothappy" class="emoticon emoticon-robothappy" src="https://communities.sas.com/i/smilies/16x16_robot-happy.png" alt="Robot Happy" title="Robot Happy" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data gamdist;
  input cust_xref_id 1-6 Fico 9-12 rsn_cd1 13-15 rsn_cd2 17-19 Yr_Month $21-28;
  cards;
15013   668 39  18  2014-01 
15013   668 39  18  2014-02 
15013   668 39  18  2014-03 
15013   670 39  18  2014-04 
15013   678 39  18  2014-05 
15013   638 38  20  2014-07 
15013   635 38  20  2014-08 
15013   635 38  20  2014-09 
15013   643 38  20  2014-10 
15013   643 38  20  2014-11 
15013   648 38  24  2014-12 
15013   648 38  24  2015-01 
15013   648 38  24  2015-02 
15013   651 38  24  2015-04 
15013   653 38  24  2015-05 
15013   653 38  24  2015-07 
15013   654 38  24  2015-08 
15013   661 38  24  2015-09 
15013   662 38  24  2015-10 
15013   662 38  24  2015-11
;
run;


%MACRO DoTranspose(variable_name, dataset_name);

  proc transpose data=work.gamdist
    out=work.&amp;amp;dataset_name(drop=_NAME_) prefix=&amp;amp;variable_name._;
    by cust_xref_id;
    id Yr_Month;
    var &amp;amp;variable_name;
  run;

%MEND;

%DoTranspose(Fico,    step1);
%DoTranspose(rsn_cd1, step2);
%DoTranspose(rsn_cd2, step3);


PROC SQL;
  /* come up with a way to reorder variables */
  /* the variable names have a hyphen (-) so variable names must look something like this: "Fico_2014-01"n */
  SELECT CAT('"Fico_', STRIP(Yr_Month), '"n ', '"rsn_cd1_', STRIP(Yr_Month), '"n ', '"rsn_cd2_', STRIP(Yr_Month), '"n ')
  INTO :ordered_variable_list SEPARATED BY ' ' 
  FROM gamdist
  ORDER BY Yr_Month;
QUIT;
%put &amp;amp;ordered_variable_list;


DATA work.combined;
  /* reorder variables */
  ATTRIB cust_xref_id &amp;amp;ordered_variable_list label='';
  MERGE work.step1 work.step2 work.step3;
  BY cust_xref_id;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 19:20:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237881#M14813</guid>
      <dc:creator>hbi</dc:creator>
      <dc:date>2015-12-04T19:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: long to wide</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237900#M14821</link>
      <description>&lt;P&gt;Make your data long and do a single transpose:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data temp;
set gamdist; 
array v{*} Fico -- rsn_cd2;
suffix = translate(Yr_Month, "_", "-");
do i = 1 to dim(v);
    var = catx("_", vname(v{i}), suffix);
    value = v{i};
    output;
    end;
run;

proc transpose data=temp out=want(drop=_name_);
by cust_xref_id; /* add NOTSORTED if needed */
var value;
id var;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Dec 2015 21:33:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/long-to-wide/m-p/237900#M14821</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-12-04T21:33:32Z</dc:date>
    </item>
  </channel>
</rss>

