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

Hi. In my dataset I have a variable has format numeric 8.. I would like to change it to YYYYMMDD without '-' or '/'.

 

All records' perfdate is '200906'. However, my result 'hidate' is '1920-09-06', which is not what I want. I want them to be '20090531' (the month end before perfdate). Thanks.

 

data B;
	set A;
	hidate = input(put(perfdate - 1, 8.), yymmdd10.);
	format hidate yymmdd10.;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data want;
num_date=200906;
want_date=intnx('month',input(put(num_date,8. -l),yymmn6.),-1,'e');
format want_date yymmddn8.;
run;

View solution in original post

5 REPLIES 5
Reeza
Super User
What does your input values look like? 200906?

And then you want that incremented to the previous month end date?
newboy1218
Quartz | Level 8
yeah 😃
novinosrin
Tourmaline | Level 20

data want;
num_date=200906;
want_date=intnx('month',input(put(num_date,8. -l),yymmn6.),-1,'e');
format want_date yymmddn8.;
run;
newboy1218
Quartz | Level 8
Amazing. Thank you so much!
Tom
Super User Tom
Super User

You are subtracting one in the wrong place. You are using the wrong informat for reading a string that is missing the day of the month.

data A;
 perfdate=200906;
run;
data B;
  set A ;
  hidate = input(put(perfdate, 6.), yymmn6.)-1;
  format hidate yymmdd10.;
run;
proc print;
run;
Obs    perfdate        hidate

 1      200906     2009-05-31

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 5 replies
  • 19906 views
  • 3 likes
  • 4 in conversation