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-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

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