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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 9010 views
  • 1 like
  • 3 in conversation