BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
y3arire_7
Fluorite | Level 6

Hi Is anyone here could share how to write the code to reflect the results "Active Status" as below?

 

I would like to have a field to reflect whether the customer is still active based on the subscription term ( month).

 

For example, when the subscription term is 24 months, the active status will be flagged as "Y" for the next 23 months.

 

Really really appreciate if anyone could shed the light on this question.

Thank you so much!

 

YYYYMMCustomerSubscription TermActive Status
20171211Y
20180113Y
201802124Y
2018031 Y
2018041 Y
2018051 Y
2018061 Y
2018071 Y
2018081 Y
2018091 Y
2018101 Y
2018111 Y
2018121 Y
2019011 Y
2019021 Y
2019031 Y
2019041 Y
2019051 Y
2019061 Y
2019071 Y
2019081 Y
2019091 Y
2019101 Y
2019111 Y
2019121 Y
2020011 Y
2017123  
2018013  
2018023  
20180336Y
2018043 Y
2018053 Y
20180637Y
2018073 Y
2018083 Y
2018093 Y
2018103 Y
2018113 Y
2018123 Y
2019013  
2019023  
2019033  
2019043  
2019053  
2019063  
2019073  
2019083  
2019093  
2019103  
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Do something like this

 

data have;
input date:yymmn6. Customer $ SubscriptionTerm;
infile datalines dsd missover;
datalines;
201712,1,1
201801,1,3
201802,1,24
201803,1, 
201804,1, 
201805,1, 
201806,1, 
201807,1, 
201808,1, 
201809,1, 
201810,1, 
201811,1, 
201812,1, 
201901,1, 
201902,1, 
201903,1, 
201904,1, 
201905,1, 
201906,1, 
201907,1, 
201908,1, 
201909,1, 
201910,1, 
201911,1, 
201912,1, 
202001,1, 
201712,3, 
201801,3, 
201802,3, 
201803,3,6
201804,3, 
201805,3, 
201806,3,7
201807,3, 
201808,3, 
201809,3, 
201810,3, 
201811,3, 
201812,3, 
201901,3, 
201902,3, 
201903,3, 
201904,3, 
201905,3, 
201906,3, 
201907,3, 
201908,3, 
201909,3, 
201910,3, 
;

data want(drop=_temp);
   do until (last.Customer);
      set have;
      by Customer;
      if not missing(SubscriptionTerm) then do;
         _temp=SubscriptionTerm;
         ActiveStatus='Y';
      end;
      else do;
         if _temp>0 then ActiveStatus='Y';
         else ActiveStatus=' ';
      end;
      _temp=_temp-1;
      output;
   end;
   format date yymmn6.;
run;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Do something like this

 

data have;
input date:yymmn6. Customer $ SubscriptionTerm;
infile datalines dsd missover;
datalines;
201712,1,1
201801,1,3
201802,1,24
201803,1, 
201804,1, 
201805,1, 
201806,1, 
201807,1, 
201808,1, 
201809,1, 
201810,1, 
201811,1, 
201812,1, 
201901,1, 
201902,1, 
201903,1, 
201904,1, 
201905,1, 
201906,1, 
201907,1, 
201908,1, 
201909,1, 
201910,1, 
201911,1, 
201912,1, 
202001,1, 
201712,3, 
201801,3, 
201802,3, 
201803,3,6
201804,3, 
201805,3, 
201806,3,7
201807,3, 
201808,3, 
201809,3, 
201810,3, 
201811,3, 
201812,3, 
201901,3, 
201902,3, 
201903,3, 
201904,3, 
201905,3, 
201906,3, 
201907,3, 
201908,3, 
201909,3, 
201910,3, 
;

data want(drop=_temp);
   do until (last.Customer);
      set have;
      by Customer;
      if not missing(SubscriptionTerm) then do;
         _temp=SubscriptionTerm;
         ActiveStatus='Y';
      end;
      else do;
         if _temp>0 then ActiveStatus='Y';
         else ActiveStatus=' ';
      end;
      _temp=_temp-1;
      output;
   end;
   format date yymmn6.;
run;
Ksharp
Super User

I know you got the answer, But I want give it a try because I love this kind of question.

 

data have;
input date:yymmn6. Customer $ SubscriptionTerm;
infile datalines dsd missover;
datalines;
201712,1,1
201801,1,3
201802,1,24
201803,1, 
201804,1, 
201805,1, 
201806,1, 
201807,1, 
201808,1, 
201809,1, 
201810,1, 
201811,1, 
201812,1, 
201901,1, 
201902,1, 
201903,1, 
201904,1, 
201905,1, 
201906,1, 
201907,1, 
201908,1, 
201909,1, 
201910,1, 
201911,1, 
201912,1, 
202001,1, 
201712,3, 
201801,3, 
201802,3, 
201803,3,6
201804,3, 
201805,3, 
201806,3,7
201807,3, 
201808,3, 
201809,3, 
201810,3, 
201811,3, 
201812,3, 
201901,3, 
201902,3, 
201903,3, 
201904,3, 
201905,3, 
201906,3, 
201907,3, 
201908,3, 
201909,3, 
201910,3, 
;
data have;
 set have;
 by Customer;
 if first.Customer then n=0;
 n+1;
run;

data key;
 set have(where=(SubscriptionTerm is not missing) keep=Customer SubscriptionTerm n);
 output;
 do i=1 to SubscriptionTerm-1 ;
  n=n+1;output;
 end;
 keep Customer n;
run;
data want;
 if _n_=1 then do;
   if 0 then set key;
   declare hash h(dataset:'key');
   h.definekey('Customer','n');
   h.definedone();
 end;
set have;
if h.check()=0 then flag='Y';
run; 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1037 views
  • 0 likes
  • 3 in conversation