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!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1092 views
  • 1 like
  • 2 in conversation