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

Hi,

I am relatively new at this and always find this tricky i have fields that are like 1/7/2011 12/11/2013 etc, and they are text, how do i turn these into proper sas dates.

Thanking in advance,

Stan

1 ACCEPTED SOLUTION

Accepted Solutions
Stan_G
Calcite | Level 5

I found the solution here it is:

data want;

set have;

new_date = input (date,ddmmyy10.) ;

  format new_date ddmmyy10. ;

put _all_ ;

run;

View solution in original post

11 REPLIES 11
Scott_Mitchell
Quartz | Level 8

Are these dates in text files or a sas dataset?

Stan_G
Calcite | Level 5

These are variables within a dataset, I've tried  this:

data _null_;

a='1/7/2011';

b=input(put(a,8.),mmddyy10.);

put b/b=mmddyy10.;

run;

but that dont seem to work, any other suggestions will be greatly apreciated.

Many thanks,

Stan

slchen
Lapis Lazuli | Level 10

data have;

input date :$10.;

_date=input(strip(date),mmddyy10.);

format _date mmddyy10.;

cards;

1/7/2011

2/19/2011

10/13/2012

12/11/2013

;

run;

Stan_G
Calcite | Level 5

sorry mate how would you do the same on the existing data set rather than the one you have created?

Many thanks,

stan

slchen
Lapis Lazuli | Level 10

data want;

  set have;

  _date=input(strip(date),mmddyy10.);

  format _date mmddyy10.;

run;

Stan_G
Calcite | Level 5

the strip function didnt seem to work, aim on sas 9.2

RichardinOz
Quartz | Level 8

If strip() is not available use trim(left(...))

Richard

slchen
Lapis Lazuli | Level 10

data _null_;

a='1/7/2011';

b=input(put(a,8.),mmddyy10.);

put b/b=mmddyy10.;

run;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Per slchen you would use the input function to convert text strings into numeric variables (which are what date/time variables are in SAS).  The input requires you to specify the format of the data, length.  So in your example your date value is 10 characters, mm/dd/yyyy, spaces are interpreted as 0.  So the format to read this in would be mmddyy10.  If you have only a two digit year then: mm/dd/yy, so the format is mmddyy8.  The input reads in the text string and converts it to numeric SAS date which can have a format applied to it to show the date representation - otherwise you will just see a number.  The reverse of course is put which takes a numeric and puts it into a character string.

Fugue
Quartz | Level 8

Kinda looks like the same question as the just-posted https://communities.sas.com/message/215994#215994

Stan_G
Calcite | Level 5

I found the solution here it is:

data want;

set have;

new_date = input (date,ddmmyy10.) ;

  format new_date ddmmyy10. ;

put _all_ ;

run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 21342 views
  • 0 likes
  • 6 in conversation