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

Hi,

I want to run this code but clearly I missed something.

Any help please?

Thank you.

HC

data a; set timehour;
if date='11/29/17'd ;run;


but this one works

data a; set timehour;
if date='29NOV17'd ;
if date='29NOV2017'd ;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If does not make any difference what format is attached to your variable. Date constants are always expressed using strings in a form that the DATE informat can recognize.

 

Dates are stored in SAS as the number of days since '01JAN1960'd.  There are many formats that work with date values so that you can print them in a form that is understandable to you.  If fact you can attach any numeric format to them.

 

565  data _null_;
566    date='29NOV2017'd ;
567    put (4*date) (date11. +1 mmddyy10. +1 yymmdd10. +1 comma7. ) ;
568  run;

29-NOV-2017 11/29/2017 2017-11-29  21,152

 

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

Doesn't look like you missed anything to me.  Date literals must use the DATE format.

hhchenfx
Barite | Level 11

The format of the date is :MMDDYY8.

and here is the notice:

 

10581
10582 data a; set timehour;
10583 if date='11/29/17'd ;run;
-----------
77
ERROR: Invalid date/time/datetime constant '11/29/17'd.

ERROR 77-185: Invalid number conversion on '11/29/17'd.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.A may be incomplete. When this step was stopped there were 0 observations
and 10 variables.
WARNING: Data set WORK.A was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

ChrisBrooks
Ammonite | Level 13

The format of your date constant is invalid - it has to be the day of the month, the three letter abbreviation of the month and the year (all in quotes) followed by a d. In your case that would be '29NOV2017'd

Tom
Super User Tom
Super User

If does not make any difference what format is attached to your variable. Date constants are always expressed using strings in a form that the DATE informat can recognize.

 

Dates are stored in SAS as the number of days since '01JAN1960'd.  There are many formats that work with date values so that you can print them in a form that is understandable to you.  If fact you can attach any numeric format to them.

 

565  data _null_;
566    date='29NOV2017'd ;
567    put (4*date) (date11. +1 mmddyy10. +1 yymmdd10. +1 comma7. ) ;
568  run;

29-NOV-2017 11/29/2017 2017-11-29  21,152

 

Kurt_Bremser
Super User

SAS has only one syntax for date literals, the one that worked (either 2- or 4-digit years). If you want to compare your date with another date format, use either put() or input() functions:

if put(mydate,yymmddd10.) = '2017-12-08' then .....;
if mydate = input('2017-12-08',yymmdd10.) then ......;
ballardw
Super User

However dates past year 9999 must use a 5 digit year in a literal and cannot exceed 31DEC20000. Smiley Wink

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