The data look like this:
data temp;
input Var1 Var2;
datalines;
5 .
7 .
8 .
2 1
3 1
1 2
1 4
4 5
6 5
6 7
6 8
;
run;
The idea is: there are cases where values of Var1 are equal to values of Var2 elsewhere while the corresponding values of Var2 are missing (values 5, 7, 8). The other specifications are not important I think.
How can I select values of Var2 as specified above (5, 7, 😎 and turn them into missing (or whatever value)? That way it looks like:
5 .
7 .
8 .
2 1
3 1
1 2
1 4
4 .
6 .
6 .
6 .
Like this:
proc sql;
create table want as
select
a.var1,
case
when missing(b.var1) then a.var2
else b.var2
end as var2
from
temp as a left join
temp as b on a.var2=b.var1;
quit;
PG
Something like this.....
proc sql;
select distinct var2 into :var2values separated by ' '
from temp
where var2 ne .
;
select var1 into :missvar separated by ' '
from temp
where var2 eq . and var1 in (&var2values)
;
quit;
data out;
set temp;
if var2 in (&missvar) then var2 = .;
run;
//Fredrik
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.