BookmarkSubscribeRSS Feed
brophymj
Quartz | Level 8

If I want to write code that changes the value of 2 or more fields if another field has a certain value i normally write

If Field1 = 'X' then do:

  Field2 = 'Y';

  Field3 = 'Z';

end;

Instead of using If-do is there a way you can write it like if Field1 = 'X' then Field2 = 'Y' and Field3 = 'Z'??

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Not that I know of.  Your if syntax above looks fine to me, and reads far better than a long string version such as you request, e.g. I can instantly see that there are two variables being manipulated and what is assigned simply by observing the indented text, it would really bug me if I started seeing code like:

if a=b then a=2 and b=5 and c=5 and d=3 and e=e and...;

Kurt_Bremser
Super User

"and" is a logical operator and not a tool to string statements together.

If you are inclined to write unreadable spaghetti code, "if field1='X' then do;field2='Y';field3='Z';end;" in one line will do nicely.

/sarcasm

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
  • 2 replies
  • 683 views
  • 0 likes
  • 3 in conversation