BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sfmeier
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
PaulLee
Fluorite | Level 6

Rather than writing the date as '01Jan2012'd, that will just be interpereated as text? Use this instead...

%sysfunc(putn('01Jan2012'd,5.))

View solution in original post

4 REPLIES 4
sfmeier
Obsidian | Level 7

The first line must be

%LET &stichtag=20111230;


PaulLee
Fluorite | Level 6

Rather than writing the date as '01Jan2012'd, that will just be interpereated as text? Use this instead...

%sysfunc(putn('01Jan2012'd,5.))

sfmeier
Obsidian | Level 7

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?

Tom
Super User Tom
Super User

Use %SYSEVALF() to let the macro code evaluate the date comparisons.

%IF %sysevalf(&stichdatum < '01Jan2012'd)

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 9389 views
  • 1 like
  • 3 in conversation