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.

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