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

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

1 ACCEPTED SOLUTION

Accepted Solutions
qoit
Pyrite | Level 9

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;

View solution in original post

2 REPLIES 2
qoit
Pyrite | Level 9

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;
Phil_NZ
Barite | Level 11

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.

Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 565 views
  • 2 likes
  • 3 in conversation