<?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: sas enumeration variable for next 6 months in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sas-enumeration-variable-for-next-6-months/m-p/295220#M61674</link>
    <description>Thank you Haikuo for your input. I wish there was a way to accept multiple solutions.</description>
    <pubDate>Tue, 30 Aug 2016 15:25:11 GMT</pubDate>
    <dc:creator>sebster24</dc:creator>
    <dc:date>2016-08-30T15:25:11Z</dc:date>
    <item>
      <title>sas enumeration variable for next 6 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-enumeration-variable-for-next-6-months/m-p/295164#M61654</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have made a similar query earlier, but since the topic has been closed off, i have to restart again as I found even more complications.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;DATA:&lt;/STRONG&gt; The input data is unsorted and hence I am using hash tables to take the input data, do some iterations, sort and then output.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;What I want&lt;/STRONG&gt;: I am trying to enumerate a table variable "answer" with binary values (0/1) if variable filter = "Y" for the next 6 month observations with the same client. In some instances, the client is missing from some monthly observations eg: client FG5151 is missing from September and October 2006. In short if variable filter "Y" then this observation and the next 6 months observations for same client should be assigned variable "answer" eq 1, else 0.&lt;/P&gt;
&lt;P&gt;Also, I would like to highlight which end of month observations&amp;nbsp;the client is missing (table : WANT2). eg: for client FG5151, i should have a table noting what months the client is missing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input client $ dates date9. filter $;
datalines ;
Fg5151 28.Feb.06 N
Fg5151 31.Mar.06 N
Fg5151 30.Apr.06 N
Fg5151 31.May.06 Y
Fg5151 30.Jun.06 N
Fg5151 31.Jul.06 Y
Fg5151 31.Aug.06 N
Fg5151 30.Nov.06 N
Fg5151 31.Dec.06 N
Fg5151 31.Jan.07 N
A101 28.Feb.06 N
A101 31.Mar.06 N
A101 30.Apr.06 Y
A101 31.May.06 N
A101 30.Jun.06 N
A101 31.Jul.06 N
ABC123 31.Mar.06 N
;



data want;
input client $ dates date9. filter $ answer $;
datalines ;
A101 28.Feb.06 N 0
A101 31.Mar.06 N 0
A101 30.Apr.06 Y 1
A101 31.May.06 N 1
A101 30.Jun.06 N 1
A101 31.Jul.06 N 1
ABC123 31.Mar.06 N 0
Fg5151 28.Feb.06 N 0
Fg5151 31.Mar.06 N 0
Fg5151 30.Apr.06 N 0
Fg5151 31.May.06 Y 1
Fg5151 30.Jun.06 N 1
Fg5151 31.Jul.06 Y 1
Fg5151 31.Aug.06 N 1
Fg5151 30.Nov.06 N 1
Fg5151 31.Dec.06 N 1
Fg5151 31.Jan.07 N 0
;

data want2;
input client $ dates date9. filter $;
datalines ;
Fg5151 30.Sep.06 N 1
Fg5151 30.Oct.06 N 1
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;User RW9 had solved a similar issue earlier, but by counting the number of observations instead of months:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  retain answer c;
  if _n_=1 or lag(client) ne client then do;
    answer=0;
    c=0;
  end;
  if filter="Y" then do;
  	call symput('xdate',dates);
    answer=1;
    c=1;
  end;
  else if answer=1 then c=c+1;
  if (intnx("month",dates,6,"same")) then do;
    answer=0;
    c=0;
  end;
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;My brain is totally fried from trying a solution.&lt;/P&gt;
&lt;P&gt;I would be really grateful if someone could help me out in this endeavour.&lt;/P&gt;
&lt;P&gt;thanks.&lt;/P&gt;
&lt;P&gt;sebastian&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2016 13:58:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-enumeration-variable-for-next-6-months/m-p/295164#M61654</guid>
      <dc:creator>sebster24</dc:creator>
      <dc:date>2016-08-30T13:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: sas enumeration variable for next 6 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-enumeration-variable-for-next-6-months/m-p/295177#M61662</link>
      <description>&lt;PRE&gt;

data have;
input client $ dates : date9. filter $;
year=year(dates);
month=month(dates);
format dates date9.;
datalines ;
Fg5151 28.Feb.06 N
Fg5151 31.Mar.06 N
Fg5151 30.Apr.06 N
Fg5151 31.May.06 Y
Fg5151 30.Jun.06 N
Fg5151 31.Jul.06 Y
Fg5151 31.Aug.06 N
Fg5151 30.Sep.06 N
Fg5151 31.Oct.06 N
Fg5151 30.Nov.06 N
Fg5151 31.Dec.06 N
Fg5151 01.Jan.07 N
A101 28.Feb.06 N
A101 31.Mar.06 N
A101 30.Apr.06 Y
A101 31.May.06 N
A101 30.Jun.06 N
A101 31.Jul.06 N
ABC123 31.Mar.06 N
;
run;
data key;
 set have(where=(filter='Y'));
 output;
 do i=1 to 5;
  dates=intnx('month',dates,1);
  year=year(dates);
  month=month(dates);
  output;
 end;
 drop i;
run;
data want;
 if _n_=1 then do;
  declare hash h(dataset:'key',hashexp:20);
  h.definekey('client','year','month');
  h.definedone();
 end;
set have;
if h.check()=0 then answer=1;
 else answer=0;
run;

&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Aug 2016 14:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-enumeration-variable-for-next-6-months/m-p/295177#M61662</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-30T14:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: sas enumeration variable for next 6 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-enumeration-variable-for-next-6-months/m-p/295178#M61663</link>
      <description>&lt;PRE&gt;

data have;
input client $ dates : date9. filter $;
year=year(dates);
month=month(dates);
format dates date9.;
datalines ;
Fg5151 28.Feb.06 N
Fg5151 31.Mar.06 N
Fg5151 30.Apr.06 N
Fg5151 31.May.06 Y
Fg5151 30.Jun.06 N
Fg5151 31.Jul.06 Y
Fg5151 31.Aug.06 N
Fg5151 30.Sep.06 N
Fg5151 31.Oct.06 N
Fg5151 30.Nov.06 N
Fg5151 31.Dec.06 N
Fg5151 01.Jan.07 N
A101 28.Feb.06 N
A101 31.Mar.06 N
A101 30.Apr.06 Y
A101 31.May.06 N
A101 30.Jun.06 N
A101 31.Jul.06 N
ABC123 31.Mar.06 N
;
run;
data key;
 set have(where=(filter='Y'));
 output;
 do i=1 to 5;
  dates=intnx('month',dates,1);
  year=year(dates);
  month=month(dates);
  output;
 end;
 drop i;
run;
data want;
 if _n_=1 then do;
  declare hash h(dataset:'key',hashexp:20);
  h.definekey('client','year','month');
  h.definedone();
 end;
set have;
if h.check()=0 then answer=1;
 else answer=0;
run;

&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Aug 2016 14:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-enumeration-variable-for-next-6-months/m-p/295178#M61663</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-30T14:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: sas enumeration variable for next 6 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-enumeration-variable-for-next-6-months/m-p/295207#M61673</link>
      <description>&lt;P&gt;An alternative without using Hash,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input client $ dates date9. filter $;
	format dates date9.;
	datalines;
Fg5151 28.Feb.06 N
Fg5151 31.Mar.06 N
Fg5151 30.Apr.06 N
Fg5151 31.May.06 Y
Fg5151 30.Jun.06 N
Fg5151 31.Jul.06 Y
Fg5151 31.Aug.06 N
Fg5151 30.Nov.06 N
Fg5151 31.Dec.06 N
Fg5151 31.Jan.07 N
A101 28.Feb.06 N
A101 31.Mar.06 N
A101 30.Apr.06 Y
A101 31.May.06 N
A101 30.Jun.06 N
A101 31.Jul.06 N
ABC123 31.Mar.06 N
;

data want want2;
	set have;
	by client notsorted;
	_gap=intck('month',dates,lag(dates));
	_dates=dates;
	format _dates date9.;

	if first.client then
		do;
			_gap=-1;
			_ct=constant('big');
		end;

	do _gap=_gap by 1 to -1;
		dates=intnx('month',_dates,(_gap+1),'e');

		if filter='Y' then
			do;
				_ct=0;
				answer=1;
			end;

		_ct+1;

		if _ct&amp;gt;6 then
			answer=0;

		if _gap &amp;lt;-1 then
			output want2;
		else output want;
	end;

	retain answer;
	drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Aug 2016 15:00:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-enumeration-variable-for-next-6-months/m-p/295207#M61673</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-08-30T15:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: sas enumeration variable for next 6 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-enumeration-variable-for-next-6-months/m-p/295220#M61674</link>
      <description>Thank you Haikuo for your input. I wish there was a way to accept multiple solutions.</description>
      <pubDate>Tue, 30 Aug 2016 15:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-enumeration-variable-for-next-6-months/m-p/295220#M61674</guid>
      <dc:creator>sebster24</dc:creator>
      <dc:date>2016-08-30T15:25:11Z</dc:date>
    </item>
  </channel>
</rss>

