Hi,
I have a character date that need to be imputed with dates containing '00' (day) to '01' & '000' (month) to 'jan':
data:
00-000-2013
20-000-2013
00-dec-2013
want:
01-jan-2013
20-jan-2013
01-dec-2013
A simple SUBSTR should do it:
data have;
infile datalines;
input date_str $20.;
format want_date_str $20.;
want_date_str = date_str;
if substr(date_str,1,2) = '00' then
substr(want_date_str,1,2) = '01';
if substr(date_str,4,3) = '000' then
substr(want_date_str,4,3) = 'JAN';
datalines;
00-000-2013
20-000-2013
00-dec-2013
;
run;
A simple SUBSTR should do it:
data have;
infile datalines;
input date_str $20.;
format want_date_str $20.;
want_date_str = date_str;
if substr(date_str,1,2) = '00' then
substr(want_date_str,1,2) = '01';
if substr(date_str,4,3) = '000' then
substr(want_date_str,4,3) = 'JAN';
datalines;
00-000-2013
20-000-2013
00-dec-2013
;
run;
Hi @qoit
A great code, I also thought of using substr but I did not know that substr can be used to output.
Btw, just adjust the "JAN" in your code to "jan" to align with @HitmonTran 's requirement.
Warm.
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.