BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
djbateman
Lapis Lazuli | Level 10

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?

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisWard
SAS Employee

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

4 REPLIES 4
DBailey
Lapis Lazuli | Level 10

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;

djbateman
Lapis Lazuli | Level 10

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

ChrisWard
SAS Employee

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;

LinusH
Tourmaline | Level 20

You forgot to add the date literal after &Sysdate.

Data never sleeps

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 4086 views
  • 6 likes
  • 4 in conversation