LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 1996, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 12 Jul 1996 15:01:47 +0100
Reply-To:     Nelson Kinnersley <nelson@DIRCON.CO.UK>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Nelson Kinnersley <nelson@DIRCON.CO.UK>
Subject:      Query with macro resolving

SAS-L,

Perhaps the following is a well known feature but it was unexpected to me when I found it happening, so I thought I would see how many others were unaware of it.

If I want to apply some conditional statements within a macro I usually test if the macro argument is blank. For example in the the following I want to conditionally apply a WHERE statement if the macro argument contains a string (similarly for applying a BY statement):

%IF &where NE %THEN %DO; WHERE &where; %END;

This works fine if &where is a simple expression e.g. day eq 1 but the %IF clause evaluates to FALSE if it is a composite expression e.g. day eq 1 and sex eq 1

I know that a workaround is to enclose &where with brackets in the %IF statement but I still don't fully understand why it fails on composite clauses.

Anybody got any insight or is this news to you?

I've included some SAS code below to reproduce the problem (a stripped down version of the original problem in which the WHERE statement was within a PROC FREQ).

Nelson

title 'Test Data'; * Set-up some test data; data testdata; do a=1 to 3; do b=1 to 4; c=int(100*ranuni(a*b)); output; end; end; run;

proc print;run;

options mprint mlogic symbolgen;

%macro test(indata=,where=,outdata=);

data &outdata; set &indata; %if &where ne %then %do; where &where; %end; run;

%mend test;

%test(indata=testdata,where=a eq 1,outdata=testout1);

title2 'Correctly Applies WHERE clause - so datasets differ'; proc compare data=testdata compare=testout1; run;

%test(indata=testdata,where=a eq 1 and b eq 1,outdata=testout2);

title2 'WHERE clause evaluates to FALSE and so datasets identical - WRONG'; proc compare data=testdata compare=testout2; run;


Back to: Top of message | Previous page | Main SAS-L page