<?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 Wide to Long and calculate 12 months prior to base month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-and-calculate-12-months-prior-to-base-month/m-p/933583#M367155</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set with one row for each customer with 2 fields: CustID and YYYYMM (year month).&lt;/P&gt;
&lt;P&gt;I want to create for each customer 12 rows with&amp;nbsp; information of 12 months&amp;nbsp; (till 11 months prior to YYYYMM)&lt;/P&gt;
&lt;P&gt;What is the way ti create want data set via code that calculate it?&lt;/P&gt;
&lt;P&gt;In real life I have 100,000 customers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Input CustID YYYYMM;
cards;
1 202201
2 202303
;
Run;

Data want;
Input CustID Position YYYYMM;
cards;
1 0 202201
1 -1 202112
1 -2 202111
1 -3 202110
1 -4 202109
1 -5 202108
1 -6 202107
1 -7 202106
1 -8 202105
1 -9 202104
1 -10 202103
1 -11 202102
2 0 202303
2 -1 202302
2 -2 202301
2 -3 202212
2 -4 202211
2 -5 202210
2 -6 202209
2 -7 202208
2 -8 202207
2 -9 202206
2 -10 202205
2 -11 202204
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 24 Jun 2024 16:58:53 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2024-06-24T16:58:53Z</dc:date>
    <item>
      <title>Wide to Long and calculate 12 months prior to base month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-and-calculate-12-months-prior-to-base-month/m-p/933583#M367155</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set with one row for each customer with 2 fields: CustID and YYYYMM (year month).&lt;/P&gt;
&lt;P&gt;I want to create for each customer 12 rows with&amp;nbsp; information of 12 months&amp;nbsp; (till 11 months prior to YYYYMM)&lt;/P&gt;
&lt;P&gt;What is the way ti create want data set via code that calculate it?&lt;/P&gt;
&lt;P&gt;In real life I have 100,000 customers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Input CustID YYYYMM;
cards;
1 202201
2 202303
;
Run;

Data want;
Input CustID Position YYYYMM;
cards;
1 0 202201
1 -1 202112
1 -2 202111
1 -3 202110
1 -4 202109
1 -5 202108
1 -6 202107
1 -7 202106
1 -8 202105
1 -9 202104
1 -10 202103
1 -11 202102
2 0 202303
2 -1 202302
2 -2 202301
2 -3 202212
2 -4 202211
2 -5 202210
2 -6 202209
2 -7 202208
2 -8 202207
2 -9 202206
2 -10 202205
2 -11 202204
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Jun 2024 16:58:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-and-calculate-12-months-prior-to-base-month/m-p/933583#M367155</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-06-24T16:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: Wide to Long and calculate 12 months prior to base month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-and-calculate-12-months-prior-to-base-month/m-p/933584#M367156</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    startyymm=input(put(yyyymm,6.),yymmn6.);    
    do i=0 to -11 by -1;
        yymm=intnx('month',startyymm,i);
        output;
    end;
    format yymm yymmn6.;
    drop i startyymm yyyymm;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Always work with valid SAS date values, the number of days since 01JAN1960. Thus, we need to convert your variable YYYYMM to an actual valid SAS date value via the INPUT function.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2024 17:08:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-and-calculate-12-months-prior-to-base-month/m-p/933584#M367156</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-06-24T17:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: Wide to Long and calculate 12 months prior to base month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-and-calculate-12-months-prior-to-base-month/m-p/933586#M367158</link>
      <description>&lt;P&gt;Great, here is the required solution by your code advice&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (Rename=(i=Position));
    set have;
    startyymm=input(put(yyyymm,6.),yymmn6.);    
    do i=0 to -11 by -1;
        yymm=intnx('month',startyymm,i);
        output;
    end;
    format yymm yymmn6.;
    drop  startyymm yyyymm;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Jun 2024 17:12:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-and-calculate-12-months-prior-to-base-month/m-p/933586#M367158</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-06-24T17:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: Wide to Long and calculate 12 months prior to base month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-and-calculate-12-months-prior-to-base-month/m-p/933588#M367160</link>
      <description>&lt;P&gt;Even simpler:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    startyymm=input(put(yyyymm,6.),yymmn6.);    
    do position=0 to -11 by -1;
        yymm=intnx('month',startyymm,position);
        output;
    end;
    format yymm yymmn6.;
    drop  startyymm yyyymm;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Jun 2024 17:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wide-to-Long-and-calculate-12-months-prior-to-base-month/m-p/933588#M367160</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-06-24T17:43:13Z</dc:date>
    </item>
  </channel>
</rss>

