The SAS Output Delivery System and reporting techniques

Hardcode Expiration Date

Accepted Solution Solved
Reply
Regular Contributor
Posts: 220
Accepted Solution

Hardcode Expiration Date

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?


Accepted Solutions
Solution
‎03-14-2013 09:22 AM
SAS Employee
Posts: 12

Re: Hardcode Expiration Date

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;

View solution in original post


All Replies
Super Contributor
Posts: 578

Re: Hardcode Expiration Date

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;

Regular Contributor
Posts: 220

Re: Hardcode Expiration Date

I have tried it without the %sysfunc(), but it still enters both statements.  I even changed today() to date() and had no different results.

Solution
‎03-14-2013 09:22 AM
SAS Employee
Posts: 12

Re: Hardcode Expiration Date

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;

Super User
Posts: 5,257

Re: Hardcode Expiration Date

You forgot to add the date literal after &Sysdate.

Data never sleeps
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 1378 views
  • 6 likes
  • 4 in conversation