BookmarkSubscribeRSS Feed
Ujjawal
Quartz | Level 8

Is it possible to write IF-THEN-ELSE statement under any procedure?

%macro (depvar=,numvars=,charvars=);

proc logistic data = abc descending;

class &charvars / param = ref;

model &depvar = &numvars &charvars / selection = stepwise;

run;

%mend;

I want the following statement wrapped in IF THEN condition. It should run only if an user specify variable(s) in CHARVARS parameter in the macro.

class &charvars / param = ref;

Something like this :

proc logistic data = abc descending;

%IF countw(&charvars) = 0 %THEN;

class &charvars / param = ref;

%END;

model &depvar = &numvars &charvars / selection = stepwise;

run;

2 REPLIES 2
Reeza
Super User

1. Functions in macro code you need to use %sysfunc

2. I think you mean to check if Countw is greater than 0, not equal to 0.

Perhaps something like the following:

%IF %sysfunc(countw(&charvars)) > 0 %THEN;

class &charvars / param = ref;

%END;

ndp
Quartz | Level 8 ndp
Quartz | Level 8

Try this:

%IF &CHARVARS ^= %STR( ) %THEN %DO; CLASS...; %END;


SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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