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;
data want;
num_date=200906;
want_date=intnx('month',input(put(num_date,8. -l),yymmn6.),-1,'e');
format want_date yymmddn8.;
run;
data want;
num_date=200906;
want_date=intnx('month',input(put(num_date,8. -l),yymmn6.),-1,'e');
format want_date yymmddn8.;
run;
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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.