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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1123 views
  • 0 likes
  • 3 in conversation