DATA Step, Macro, Functions and more

Conditional Statement in PROC

Reply
Regular Contributor
Posts: 183

Conditional Statement in PROC

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;

Super User
Posts: 19,802

Re: Conditional Statement in PROC

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;

Contributor ndp
Contributor
Posts: 61

Re: Conditional Statement in PROC

Try this:

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


Ask a Question
Discussion stats
  • 2 replies
  • 234 views
  • 0 likes
  • 3 in conversation