SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

How to assign condition to variables that replaces non-missings but retains missings

Reply
Frequent Contributor
Posts: 75

How to assign condition to variables that replaces non-missings but retains missings

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.

Respected Advisor
Posts: 4,173

Re: How to assign condition to variables that replaces non-missings but retains missings

Posted in reply to NonSleeper

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?

Ask a Question
Discussion stats
  • 1 reply
  • 268 views
  • 1 like
  • 2 in conversation