BookmarkSubscribeRSS Feed
Dan_S
Calcite | Level 5
I was having some problems getting a SP to work with a Boolean Parameter. I have made up a mock example to simplify my code. It seem that I always return a=1 and b=1 whether my boolean value is true or false? here is my code. Thank you in advance for your help. Dan
%Global b1;

data fun;
a = 0;
b = 0;
data fun;
set fun;
if &b1=true then
do;
a = 1;
b = 1;
end;
proc print;
run;
1 REPLY 1
Olivier
Pyrite | Level 9
I would think that it's rather a macro logic problem than a stored process problem.
When you write a SAS statement like the IF statement, it is not processed by the macro facility.
Hence what you write is either :

IF true = true THEN DO ; etc.

or

IF false = true THEN DO ; etc.

From a SAS (and not macro) point of view, this means you are comparing values for variables named TRUE or FALSE. Not that you're comparing text strings "TRUE" or "FALSE", which would require quotes around the value itself.
As the variables TRUE and FALSE don't exist in your dataset, they are created with missing values (you should see them in the printed output). Your condition, in every case, ends up as :
IF . = . THEN ...
which is always true.

I would transform your program into :

%Global b1;
data fun;
a = 0;
b = 0;
data fun;
set fun;
if "%UPCASE(&b1)"="TRUE" then
do;
a = 1;
b = 1;
end;
proc print;
run;

another solution is to use the macro-IF, for which everything is just plain text and then, no quotes needed anywhere.

%Global b1;

data fun;
a = 0;
b = 0;
data fun;
set fun;
%if &b1=true %then
%do;
a = 1;
b = 1;
%end;
proc print;
run;

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
  • 1 reply
  • 841 views
  • 0 likes
  • 2 in conversation