BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sas_R
Calcite | Level 5

Hello,

I have a question for getting the next non missing value for the same variable, in other words I'm trying to move up the non missing values so my missing value will be at the bottom of the variable. Below table is the example that I'm trying to create, how can I do that with SAS procedure ?  Thank you.

XYY_New
155
2.7
376
46.
1 ACCEPTED SOLUTION

Accepted Solutions
yaswanthj
Fluorite | Level 6

Hi..

Im not sure the result, in which scenario do you really want.. here is the simple code using many to many merge..

data have;

input x y ;

cards;

1 5

2 .

3 7

4 6

5 .

6 .

7 3

;

run;

proc print data = have;

run;

data want;

merge have(keep = x) have(keep = y where = (y is not missing));

run;

proc print;

run;

Thanks,

Yash

View solution in original post

3 REPLIES 3
PGStats
Opal | Level 21

Maybe your example is oversimplified... but this would do it :

data want;

set have(keep=x);

if not endy

then set have(keep=y where=(y is not missing)) end=endy;

else call missing(y);

run;

PG

PG
Amarnath7
Fluorite | Level 6

with simple steps;

data in ;
input x y;
ord=_n_;
cards;
1 .
2 .
3 7
4 6
5 7
6 .
7 0
;
run;

data y;
set in (keep=y where=(y^=.));
ord=_n_;
run;


data  out;
merge in (drop=y) y;
by ord;
drop ord;
run;

yaswanthj
Fluorite | Level 6

Hi..

Im not sure the result, in which scenario do you really want.. here is the simple code using many to many merge..

data have;

input x y ;

cards;

1 5

2 .

3 7

4 6

5 .

6 .

7 3

;

run;

proc print data = have;

run;

data want;

merge have(keep = x) have(keep = y where = (y is not missing));

run;

proc print;

run;

Thanks,

Yash

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 3 replies
  • 1675 views
  • 3 likes
  • 4 in conversation