<?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: Sequence in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sequence/m-p/276596#M55431</link>
    <description>&lt;P&gt;/* create table with all months between the minimum and maximum months in the data */&lt;/P&gt;
&lt;P&gt;data yr_mo;&lt;BR /&gt;input yr mo;&lt;BR /&gt;datalines;&lt;BR /&gt;2014 12&lt;BR /&gt;2015 01&lt;BR /&gt;2015 02&lt;BR /&gt;. . .&lt;BR /&gt;2015 12&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data yr_mo; &amp;nbsp;/* add sequence field */&lt;BR /&gt; seq = _n_;&lt;BR /&gt; set yr_mo;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table temp as&lt;BR /&gt;select c.id, b.yr, b.mo&lt;BR /&gt;from yr_mo A&lt;BR /&gt;join yr_mo B on b.seq = a.seq +1 /* month after that in A */&lt;BR /&gt;join data C on c.yr = a.yr and &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/* active for month in A */&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c.mo = a.mo&lt;BR /&gt;left join data D on d.id = c.id and&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;d.yr= b.yr and&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;d.mo=b.mo&lt;BR /&gt;where missing(d.id) /* inactive for month in B */&lt;BR /&gt;;&lt;BR /&gt;proc sql;&lt;BR /&gt;select id, count(*) as row_cnt&lt;BR /&gt;from temp&lt;BR /&gt;group by id;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Jun 2016 19:11:21 GMT</pubDate>
    <dc:creator>Pamela_JSRCC</dc:creator>
    <dc:date>2016-06-10T19:11:21Z</dc:date>
    <item>
      <title>Sequence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequence/m-p/276581#M55425</link>
      <description>&lt;P&gt;My data&amp;nbsp;is attached:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;For each ID I need to determine how many times the individual changed from an active client to an inactive client. &amp;nbsp;I am stumped how to start..any ideas? &amp;nbsp;This person changed on 3/15, 6/15, 8/15 (not 9/15 or 10/15) &amp;nbsp;and 1/16&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 18:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequence/m-p/276581#M55425</guid>
      <dc:creator>Jarious</dc:creator>
      <dc:date>2016-06-10T18:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequence/m-p/276596#M55431</link>
      <description>&lt;P&gt;/* create table with all months between the minimum and maximum months in the data */&lt;/P&gt;
&lt;P&gt;data yr_mo;&lt;BR /&gt;input yr mo;&lt;BR /&gt;datalines;&lt;BR /&gt;2014 12&lt;BR /&gt;2015 01&lt;BR /&gt;2015 02&lt;BR /&gt;. . .&lt;BR /&gt;2015 12&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data yr_mo; &amp;nbsp;/* add sequence field */&lt;BR /&gt; seq = _n_;&lt;BR /&gt; set yr_mo;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table temp as&lt;BR /&gt;select c.id, b.yr, b.mo&lt;BR /&gt;from yr_mo A&lt;BR /&gt;join yr_mo B on b.seq = a.seq +1 /* month after that in A */&lt;BR /&gt;join data C on c.yr = a.yr and &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/* active for month in A */&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c.mo = a.mo&lt;BR /&gt;left join data D on d.id = c.id and&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;d.yr= b.yr and&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;d.mo=b.mo&lt;BR /&gt;where missing(d.id) /* inactive for month in B */&lt;BR /&gt;;&lt;BR /&gt;proc sql;&lt;BR /&gt;select id, count(*) as row_cnt&lt;BR /&gt;from temp&lt;BR /&gt;group by id;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 19:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequence/m-p/276596#M55431</guid>
      <dc:creator>Pamela_JSRCC</dc:creator>
      <dc:date>2016-06-10T19:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequence/m-p/276657#M55457</link>
      <description>&lt;PRE&gt;
Assuming I understand what you mean.



data have;
infile cards expandtabs truncover;
input ID	s_year	s_month;
cards;
10000057	2014	12
10000057	2015	1
10000057	2015	2
10000057	2015	4
10000057	2015	5
10000057	2015	7
10000057	2015	11
10000057	2015	12
;
run;

data temp;
 merge have have(rename=(ID=_id s_year=_year s_month=_month) firstobs=2);
 output;
 start=mdy(s_month,1,s_year);
if id=_id then do;
 n=intck('month',start,mdy(_month,1,_year))-1;
 do i=1 to n;
   dummy=1;
   temp=intnx('month',start,i);
   s_year=year(temp);
   s_month=month(temp);
   output;
 end;
end;
else if _n_ ne 1 then do;
   dummy=1;
   temp=intnx('month',start,1);
   s_year=year(temp);
   s_month=month(temp);
   output;
end;
drop _: temp n i start;
run;
data want;
 set temp;
 by id dummy notsorted;
 if first.dummy and dummy=1 then changed=1;
run;



&lt;/PRE&gt;</description>
      <pubDate>Sat, 11 Jun 2016 07:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequence/m-p/276657#M55457</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-11T07:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequence/m-p/276696#M55469</link>
      <description>&lt;P&gt;I would try it this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by id year month;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;current_date = mdy(month, 1, year);&lt;/P&gt;
&lt;P&gt;prior_date = lag(current_date);&lt;/P&gt;
&lt;P&gt;if prior_date ne intnx('month', current_date, -1) then changes + 1;&lt;/P&gt;
&lt;P&gt;if first.id then changes=0;&lt;/P&gt;
&lt;P&gt;if last.id;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes that your goal is as stated, to count the changes (not to identify the year/month). &amp;nbsp;The count actually omits anything occurring after the final observation (in this case the 1/16 change). &amp;nbsp;But you could always add 1 at the end to account for that.&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jun 2016 15:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequence/m-p/276696#M55469</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-11T15:07:15Z</dc:date>
    </item>
  </channel>
</rss>

