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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: