BookmarkSubscribeRSS Feed
NonSleeper
Quartz | Level 8

The original data looks like:

data have;

input Var1 Var2 Var3 Var4;

datalines;

1     0     .     0

1     1     1     2

1     .     .     3

0     2     3     1

;

I want to create a data that looks like:

1     0     .     0

1     0     0     0

1     .     .     0

0     2     3     1

;

The idea is if Var1 = 1 then replace all non-missing values of Var2, Var3 and Var4 to 0 and keep missing values as-is.

EDIT: Will this work?

data want; set have;

array varlist

Var 2 Var3 Var4;

do i = 1 to 4;

if Var1 = 1 and varlist(i) ne . then varlist(i) = 0;

end; drop i; run;

EDIT 2: It turns out to work. Sorry for bringing it up.

1 REPLY 1
Patrick
Opal | Level 21

What about you first mark in your previous posts which answers had been helpful and which ones correct to "close off" these threads before starting a new one?

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
  • 1 reply
  • 816 views
  • 1 like
  • 2 in conversation