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

I've imported an excel sheet into SAS EG using the import wizard and the date values are character values that look like 2013/03/01. I need to convert these to SAS Date values, but when I try to use input the values just come out as missing values. How can I properly convert these character dates to SAS date values? Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

You didn't show the code you used. The following, using the anydtdte informat worked for me:

 

data have;
  input date $10.;
  cards;
2013/03/01
2012/04/02
;
data want;
  set have (rename=(date=_date));
  format date date9.;
  date=input(_date,anydtdte10.);
run;

HTH,

Art, CEO, AnalystFinder.com

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

You didn't show the code you used. The following, using the anydtdte informat worked for me:

 

data have;
  input date $10.;
  cards;
2013/03/01
2012/04/02
;
data want;
  set have (rename=(date=_date));
  format date date9.;
  date=input(_date,anydtdte10.);
run;

HTH,

Art, CEO, AnalystFinder.com

JediApprentice
Pyrite | Level 9

@art297 This does indeed turn it into a SAS date, however ultimately what I'm trying to do after the conversion is subset a dataset by an expression:

 

proc sql noprint;                              
 select ID into :ID_List_2010 separated by ' '
 from EGTASK.'ID FROM DATES_UPDATED'n
 where from_date < '01jan2011'd;
quit;

But it is giving me the error:

 

Expression using less than  (<) has components that are of different data types.

 

Sorry, I did not specify before that I wanted to do a condition on dates.

art297
Opal | Level 21

I'd think that your log shows some other error before that. The following worked for me:

 

  input id $ date $10.;
  cards;
a 2013/03/01
b 2010/03/01
c 2010/04/02
;

data want;
  set have (rename=(date=_date));
  format from_date date9.;
  from_date=input(_date,anydtdte10.);
run;

proc sql noprint;                              
 select ID into :ID_List_2010 separated by ' '
   /* from EGTASK.'ID FROM DATES_UPDATED'n*/
   from want
     where from_date < '01jan2011'd
  ;
quit;

Art, CEO, AnalystFinder.com

SASKiwi
PROC Star

Try defining the date columns in Excel as type DATE to begin with, then re-import.

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
  • 4 replies
  • 1690 views
  • 0 likes
  • 3 in conversation