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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
unison
Lapis Lazuli | Level 10

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;
-unison

View solution in original post

2 REPLIES 2
unison
Lapis Lazuli | Level 10

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;
-unison
Joefrancis99
Calcite | Level 5

Perfect, thanks a lot!

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

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
  • 2 replies
  • 556 views
  • 1 like
  • 2 in conversation