I am working on writing a SAS code and since I am new to SAS (Have worked on R all the time), I am having trouble understanding the date formats in SAS.
I Have a SAS data set Sales_yyyymm and I am creating a code that takes the user's input of a date value, and if Sales data exists for that date, I need to create a flag as 1 else as 0. Currently I am using this code -
%Let check_date = 20010120;
Data A;
Set B;
If date=&check_date then Date_Flag = 1;
else Date_Flag = 0;
run;
date
is the Date column in my SAS data set Sales_yyyymm
and the values are like 20130129
, 20110412
, 20140120
etc.
But if I run this code, I get all my Date_Flag
values as 0. The IF condition is being ignored and I am not sure how or why this is happening.
Any idea?
Thanks!
date
column is infact a date which is formatted to show as yyyymmdd i.e., date is not a 8digit integer. Checkproc contents data =<your dataset>; run;
output and report back the type & format ofdate
column – user1509107date
column is really stored as a date type column. – user1509107date
column is of type NUM and Len 4 and format YYMMDDN8. – RHelpFormat
in SAS is solely a way to print something that looks nice to human eyes - akin to in c++ usingsprintf
. It has no bearing on the underlying value nor is it permitted to be used in equalities (without some other function, likeput
, which is the direct equivalent ofsprintf
). – Joe