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

Hello, Need help in converting a string value to date datatype in my data set.

Date was stored in string field and now I want to change it to format mmddyy10.

 

String values: 

12/03/2016

11/29/2016

 06/18/2014

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Within a DATA step:

 

newvar = input(string, mmddyy10.);

format newvar mmddyy10.;

View solution in original post

5 REPLIES 5
Astounding
PROC Star

Within a DATA step:

 

newvar = input(string, mmddyy10.);

format newvar mmddyy10.;

Tom
Super User Tom
Super User

You can use the INPUT() function. Your strings look like you should be able to use the MMDDYY informat to read them. Note that dates are numbers so you will need to make a new variable.

date = input(string,mmddyy10.);

Now that you have a date value you can attach any date format to it so that it will print in a human readable form.  If you want the date to print in MDY order then attach the MMDDYY10. format to it.

format date mmddyy10.;

But why not print the numbers using a less confusing date format where users don't have to guess whether the value represents Dec10 or Oct12?  Like DATE9. or YYMMDD10.?

Miracle
Barite | Level 11

Hi Melvin. This will answer your question.

 

Loko
Barite | Level 11

Always better to store date values as number and just to display them in the desired format:

 

data have;
infile datalines;
input d $10.;
datalines;
12/03/2016
11/29/2016
06/18/2014
 ;
 run;

data want;
set have;
d_num=input(d,mmddyy10.);

format d_num date9.;
run;
PeterClemmensen
Tourmaline | Level 20
data _null_;
input chardate:$10.;
numdate=input(chardate, mmddyy10.);
format numdate mmddyy10.;
put numdate;
datalines;
12/03/2016
11/29/2016
06/18/2014
;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 5 replies
  • 123259 views
  • 5 likes
  • 6 in conversation