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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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