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

I have a character variable with length $7. I want to convert it into a date variable with yyyymm format. However, the values of the character variable is a bit messy. For examples, there are both "2018-09" and "2018-9". I tried to use 

 

data want;
format date_new yymmn6.;
set have;
date_new = input(date_char, yymmn6.);
run;

but all of the new date variable values are missing.

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16
data want;
input date_char $;
date_new = input(cats(date_char,'-01'), anydtdte10.);
format date_new yymmn6.;
cards;
2018-09
2018-9
;
Thanks,
Jag

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16
data want;
input date_char $;
date_new = input(cats(date_char,'-01'), anydtdte10.);
format date_new yymmn6.;
cards;
2018-09
2018-9
;
Thanks,
Jag
novinosrin
Tourmaline | Level 20

Use the gorgeous compress with your original idea like

 

data have;
input   date  $;
cards;
2018-09
2018-9
;

data want;
set have;
new_date=input(compress(date,'-'),yymmn6.) ;
format new_date date9.;
run;

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 25. 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
  • 3 replies
  • 1091 views
  • 0 likes
  • 3 in conversation