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

I need to convert a character column to the date format

xliu1_0-1634673495639.png

The format I am looking for is 05/04/1995

Here are my sas code:

data degree;
set prod.shrdgmr;
grad_term=input(substr(SHRDGMR_GRAD_DATE, 1,10), mmddyy10.);
keep shrdgmr_pidm SHRDGMR_GRAD_DATE grad_term;
where shrdgmr_pidm=14921;
run;

but the output for created column grad_term is blank

xliu1_1-1634673648485.png

Any idea how I should change the code? Thanks!!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@xliu1 wrote:

I need to convert a character column to the date format

xliu1_0-1634673495639.png

The format I am looking for is 05/04/1995

Here are my sas code:

data degree;
set prod.shrdgmr;
grad_term=input(substr(SHRDGMR_GRAD_DATE, 1,10), mmddyy10.);
keep shrdgmr_pidm SHRDGMR_GRAD_DATE grad_term;
where shrdgmr_pidm=14921;
run;

but the output for created column grad_term is blank

xliu1_1-1634673648485.png

Any idea how I should change the code? Thanks!!


Why are  you attempting to read a date that starts with the year using an Informat that starts with month????

Did you read the log with all the invalid data messages??

 

Try

grad_term=input(SHRDGMR_GRAD_DATE,yymmdd10.);
format gradterm mmddyy10.;

The Informat length of 10 says to only read the first 10 characters so the substr isn't needed. The correct Informat is.

View solution in original post

2 REPLIES 2
ballardw
Super User

@xliu1 wrote:

I need to convert a character column to the date format

xliu1_0-1634673495639.png

The format I am looking for is 05/04/1995

Here are my sas code:

data degree;
set prod.shrdgmr;
grad_term=input(substr(SHRDGMR_GRAD_DATE, 1,10), mmddyy10.);
keep shrdgmr_pidm SHRDGMR_GRAD_DATE grad_term;
where shrdgmr_pidm=14921;
run;

but the output for created column grad_term is blank

xliu1_1-1634673648485.png

Any idea how I should change the code? Thanks!!


Why are  you attempting to read a date that starts with the year using an Informat that starts with month????

Did you read the log with all the invalid data messages??

 

Try

grad_term=input(SHRDGMR_GRAD_DATE,yymmdd10.);
format gradterm mmddyy10.;

The Informat length of 10 says to only read the first 10 characters so the substr isn't needed. The correct Informat is.

xliu1
Quartz | Level 8

Thanks for your response. This works out. 

 



sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 497 views
  • 0 likes
  • 2 in conversation