BookmarkSubscribeRSS Feed
NonSleeper
Quartz | Level 8

I have several variables, let's say V1 to V3, each of them containing values of 1 or 0.

How to write a statement for an array of these variables, so that a new variable (e.g., V4) will receive value of 1 if any among V1-V3 is 1; and 0 otherwise (i.e., all among V1-V3 are 0s)?

2 REPLIES 2
stat_sas
Ammonite | Level 13

data want;

set have;

if sum(of v1-v3)>0 then v4=1;

else v4=0;

run;

ballardw
Super User

v4= max(of v1-v3);

would also work.

What would you want if all of v1 - v3 are missing though?

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 832 views
  • 0 likes
  • 3 in conversation