BookmarkSubscribeRSS Feed
NonSleeper
Quartz | Level 8

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 .

2 REPLIES 2
PGStats
Opal | Level 21

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

PG
FredrikE
Rhodochrosite | Level 12

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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1195 views
  • 0 likes
  • 3 in conversation