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;
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
Doesn't look like you missed anything to me. Date literals must use the DATE format.
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
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
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
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 ......;
However dates past year 9999 must use a 5 digit year in a literal and cannot exceed 31DEC20000.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.