I need to convert a character column to the date format
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
Any idea how I should change the code? Thanks!!
@xliu1 wrote:
I need to convert a character column to the date format
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
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 wrote:
I need to convert a character column to the date format
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
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.
Thanks for your response. This works out.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.