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

Hi,

I have a date character variable in my dataset that has the following format:
type = Char
Len = 50
Format = $50.

Example of field below:

Date_char = 22-SEP-20


I have tried a number of functions (and a combination of functions) such as inputs, format, substr, cat, compress, substitution to convert this date character into a date9. format - without success.

I am sure there is an easy way to resolve this. Please advise.

 
 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have;
 Date_char = '22-SEP-20';
run;

data want;
 set have;
 sas_date=input(date_char,date9.);/*read and convert to num date*/
 format sas_date date9.;/*format the sas date for appropriate display*/
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
data have;
 Date_char = '22-SEP-20';
run;

data want;
 set have;
 sas_date=input(date_char,date9.);/*read and convert to num date*/
 format sas_date date9.;/*format the sas date for appropriate display*/
run;
Tom
Super User Tom
Super User

So your variable can hold up to 50 bytes.  The example value you showed is only 9 bytes long.  If the rest of the values follow that pattern then the DATE informat should work.  Just make sure to remove any leading spaces in the values before trying to read it with the DATE informat.

data want;
  set have;
  date_num = input(left(date_char),date11.);
  format date_num 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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3294 views
  • 1 like
  • 3 in conversation