Help using Base SAS procedures

with of withouth brackets

Reply
Super Contributor
Posts: 301

with of withouth brackets

Hi Guys,

I need to change in a macro of a standard table:

the condition emerge by the other condition aetdate=. or aetdate >= factdat

in this statment

variable=%str(emerge & trtrel)

my question is, the change has to be:

a)with brackets:

variable=%str( (aetdate=. or aetdate >= factdat) & trtrel)

b)withouth brackets

variable=%str( aetdate=. or aetdate >= factdat & trtrel)

Thanks.

Super User
Super User
Posts: 6,502

with of withouth brackets

Why do you have the %STR()?   It looks like you are referencing actual variables why would you need to do macro quoting of any type?

Super Contributor
Posts: 301

with of withouth brackets

i suppose to prevent the resolution of & or a semicolon (Smiley Wink if i need to.

Is a tot file tom, only i got for default %str()...and i need to put the condition inside of this bracket:

my question is :

this condition has to be inside of this bracket as:

a) with brackets  (aetdate=. or aetdate >= factdat) & trtrel

b) or withouth brackets  aetdate=. or aetdate >= factdat & trtrel

which is the difference?

Super User
Posts: 9,682

with of withouth brackets

Not sure what you are talking about.

It is in data step or Macro ?

Ksharp

Super Contributor
Posts: 301

with of withouth brackets

is a tot file, i.e a macro with a default expression:

%str()...and i ned to put the condition a) or b) , i am not sure........ inside of this braket..like %str(condition)...only i can change condition, anyone else.

Super User
Posts: 5,085

with of withouth brackets

Looks like you didn't need %str before, but you will need it now because of the equal sign and the added parentheses.

Yes, you need the parentheses.  Without them, SAS would logically evaluate AND first (before OR).  With them, you can force SAS to evaluate OR first which is what your example requires.

When referring to parentheses inside %STR, you need to add an extra percent sign:

variable = %str( %(aetdate=. or aetdate > factdat%) & trtrel)

Good luck.

Super Contributor
Posts: 301

with of withouth brackets

Thank you for the answer.

I did not know SAS evaluate AND first then OR.

Why I need to putthis %before (?...I  dont use these porcentages before ( as my option a of my post, and the macro works right.

Thanks.

Super User
Posts: 5,085

with of withouth brackets

Before, the parentheses were part of the %STR function, and they told SAS where to start and where to end applying the %STR function.  That still applies to the exterior parentheses in the sample solution.  They tell %STR where to start and where to end, so those parentheses don't need the extra %.

These new  parentheses are inside the %STR function.  The %STR function is being applied to those characters.  That's why %STR requires %( and %).  Since the "inside" parentheses are balanced -- you have both a left then a right parenthesis -- you can try leaving out the % and see what happens.  It might work, but I'm not able to test that right now.  It will work using %( and %).

Good luck.

Super Contributor
Posts: 301

with of withouth brackets

Please,

try and let me know, thanks.

your option: variable = %str( %(aetdate=. or aetdate > factdat%) & trtrel)

or

my option: variable = %str( (aetdate=. or aetdate > factdat) & trtrel)

we will see if there are  some differences.

Super User
Posts: 5,085

with of withouth brackets

michtka,

I tried a similar test, and found I could omit the extra %.  But if you want to learn, you should try testing it yourself.

Good luck.

Ask a Question
Discussion stats
  • 9 replies
  • 300 views
  • 6 likes
  • 4 in conversation