I am trying to create a macro bibgen, that sets the macro variable bib to a, if the date stichdatum is earlier then 01Jan2012, else to b.
Stichdatum is a date macro variable that is created by the code
--------------------------------------------------------
%LET &
%LET Stichdatum = %sysfunc(INPUTN(&stichtag, B8601DA.));
--------------------------------------------------------
Here is my macro, however it does not work. It always returns b, whereas it should return b in this case! How can I fix it?
--------------------------------------------------------
/* Makro zur automatischen Selektion der richtigen Bibliothek wg. Historisierung */
%Macro bibgen();
%GLOBAL bib;
%LET stichdatum2 = %SYSFUNC(putn(&stichdatum, date9.));
%PUT stichdatum=&stichdatum;
%PUT stichdatum2=&stichdatum2;
%IF &stichdatum < '01Jan2012'd
%THEN %LET bib =a;
%ELSE %LET bib =b;
%PUT &bib;
%mend bibGen;
Rather than writing the date as '01Jan2012'd, that will just be interpereated as text? Use this instead...
%sysfunc(putn('01Jan2012'd,5.))
The first line must be
%LET &stichtag=20111230;
Rather than writing the date as '01Jan2012'd, that will just be interpereated as text? Use this instead...
%sysfunc(putn('01Jan2012'd,5.))
Thank you! It works. However, just that I understand the reason: I always thought that SAS would evaluate the condition as sas code and not as macro code.
So would the condition be different in an regular IF-THEN-Clause? i.e.I could write '01Jan2012'd in a regular IF-THEN-Clause, coundn't I?
Use %SYSEVALF() to let the macro code evaluate the date comparisons.
%IF %sysevalf(&stichdatum < '01Jan2012'd)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.