BookmarkSubscribeRSS Feed
scb
Obsidian | Level 7 scb
Obsidian | Level 7

May I know what wrong with the macro below as I can't get the T1 dataset? Thanks.


%LET PERIODE=01sep2018;
%LET TODATE ="10sep2018"D;


DATA _NULL_;
IF INTCK('DAY',"&PERIODE"D,&TODATE.) ge 8
THEN call symputx("T", "T1");
ELSE call symputx("T", "T2");
RUN;
%PUT T=&T;

 

%macro check(dsn);
%if T = "&dsn" %then %do;
DATA T1;
SET SASHELP.CARS;
IF MAKE EQ 'BMW';
RUN;
%end;
%else %do;
DATA T2;
SET SASHELP.CARS;
RUN;
%end;
%mend check;
%check(T1);

3 REPLIES 3
Kurt_Bremser
Super User
%if T = "&dsn" %then %do;

In this macro statement, you compare the string

T

with a string that (as the macro is called later) is

"T1"

note the presence and absence of quotes.

What you probably wanted:

%if &T = &dsn %then %do;

The macro preprocessor does not need quotes when comparing strings, as everything is a string for it.

Amir
PROC Star

Hi,

 

Try changing your %if condition to:

 

%if T1 = &dsn %then %do;

 

Regards,

Amir.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

"May I know what wrong with the macro below " - its all in upper case, no use of the code window {i}, so code is next to impossible to read, no log provided to explain what is "wrong".  (all mentioned previously).

 

At a guess I would say:

%if  T

is your problem as macro variables need an & before, and should also for good coding have a . afterwards.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1263 views
  • 0 likes
  • 4 in conversation