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

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!

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