I have to hardcode some information in a program, but I want it to expire and give me a warning message in the log that the hardcode is not longer being applied. I have searched around and found an example that Jack Shostak gave in SAS Programming in the Pharmaceutical Industry. It didn't work. This is what he did:
data endstudy;
set endstudy;
**** HARDCODE APPROVED BY DR. NAME AT SPONDER ON 02/02/2005;
if subjid = "101-1002" and "&sysdate" <= "01MAY2005"d then do;
discterm = "Death";
put "Subject " subjid "hardcoded to termination reason" discterm;
end;
run;
This example doesn't work because "&sysdate" is considered a character string and is not able to compare to the date value on the other side of the inequality.
Here is a workable example of what I have also tried. It didn't work either. If you check the log, you can see that it entered both the if statement and the else statement and printed both messages.
data _null_;
if %sysfunc(today())<'01MAY2013'd then do;
%put Today is before May 1, 2013;
end;
else do;
%put Today is on or after May 1, 2013;
end;
run;
In case you are really curious, below is what my actual code looks like. This code is the exact same syntax as the example above. Again, it enters both statements. In other words, it makes the hardcoded changes AND prints the warning message.
data lesions;
set lesions;
if %sysfunc(today()) < '01MAY2013'd then do;
if subject='0001-1873' & lesno=1 & visitid=1 then asdt='04OCT2012'd;
if subject='0502-6869' & lesno=1 & asdt='08FEB2013'd then visitid=2;
if subject in ('0703-1877','0704-0001') then visitid=0;
end;
else do;
%put WARNING: There is hardcoding in this step that has expired! Make sure the data has been updated.;
end;
run;
Can anyone advise me on the correct method?
You would also need to change the put statement to non macro.
data lesions;
.....
else do;
put 'WARNING: There is hardcoding in this step that has expired! Make sure the data has been updated.';
end;
run;
Also, on the first example you would need to make SAS treat the %SYSDATE as a date also so you would need the 'd'
if subjid = "101-1002" and "&sysdate"d <= "01MAY2005"d then do;
If you're not using macros...then your data step could be rewritten without the sysfunc as
data lesions;
set lesions;
if date() < '01MAY2013'd then do;
if subject='0001-1873' & lesno=1 & visitid=1 then asdt='04OCT2012'd;
if subject='0502-6869' & lesno=1 & asdt='08FEB2013'd then visitid=2;
if subject in ('0703-1877','0704-0001') then visitid=0;
end;
else do;
%put WARNING: There is hardcoding in this step that has expired! Make sure the data has been updated.;
end;
run;
I have tried it without the %sysfunc(), but it still enters both statements. I even changed today() to date() and had no different results.
You would also need to change the put statement to non macro.
data lesions;
.....
else do;
put 'WARNING: There is hardcoding in this step that has expired! Make sure the data has been updated.';
end;
run;
Also, on the first example you would need to make SAS treat the %SYSDATE as a date also so you would need the 'd'
if subjid = "101-1002" and "&sysdate"d <= "01MAY2005"d then do;
You forgot to add the date literal after &Sysdate.
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.