BookmarkSubscribeRSS Feed
michtka
Fluorite | Level 6

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.

9 REPLIES 9
Tom
Super User Tom
Super User

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?

michtka
Fluorite | Level 6

i suppose to prevent the resolution of & or a semicolon (;) 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?

Ksharp
Super User

Not sure what you are talking about.

It is in data step or Macro ?

Ksharp

michtka
Fluorite | Level 6

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.

Astounding
PROC Star

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.

michtka
Fluorite | Level 6

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.

Astounding
PROC Star

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.

michtka
Fluorite | Level 6

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.

Astounding
PROC Star

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 9 replies
  • 1391 views
  • 6 likes
  • 4 in conversation