I'm trying to use the intnx function to define someone's end date on a promotional offer. The start date variable that I'm reading is numeric so the calculation works, however it's not reading in the dates how I want to. For example, a value in my start date variable is 201707, which I want to read in as July 2017. However, it's giving me the month equivalent of what that number represents, so 251204 (April 2512). How can i read the number in as the corresponding month?
data test;
set month_calc (keep=campaign_YYYYMM bt_duration vintage);
campaign_YYYYMM2 = campaign_YYYYMM;
format campaign_YYYYMM2 yymmn.;
bt_expiry_month = intnx('month',campaign_YYYYMM2,bt_duration);
format bt_expiry_month yymmn.;
run;
Convert your numeric yyyymm start_date to a SAS date with format yymmn6. Then you can apply intnx in the way you want:
data have;
input start_date;
datalines;
201707
;
run;
data want;
set have;
format start_date_as_date end_date yymmn6.;
start_date_as_date = input(put(start_date,z6.),yymmn6.);
end_date = intnx('month',start_date_as_date,1,'s');
run;
So to apply to your example:
data test;
set month_calc (keep=campaign_YYYYMM bt_duration vintage);
format campaign_YYYYMM2 bt_expiry_month yymmn6.;
campaign_YYYYMM2=input(put(campaign_YYYYMM, z6.), yymmn6.);
bt_expiry_month=intnx('month', campaign_YYYYMM2, bt_duration, 's');
run;
Convert your numeric yyyymm start_date to a SAS date with format yymmn6. Then you can apply intnx in the way you want:
data have;
input start_date;
datalines;
201707
;
run;
data want;
set have;
format start_date_as_date end_date yymmn6.;
start_date_as_date = input(put(start_date,z6.),yymmn6.);
end_date = intnx('month',start_date_as_date,1,'s');
run;
So to apply to your example:
data test;
set month_calc (keep=campaign_YYYYMM bt_duration vintage);
format campaign_YYYYMM2 bt_expiry_month yymmn6.;
campaign_YYYYMM2=input(put(campaign_YYYYMM, z6.), yymmn6.);
bt_expiry_month=intnx('month', campaign_YYYYMM2, bt_duration, 's');
run;
Perfect, thanks a lot!
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: