Help using Base SAS procedures

Getting next non missing value for the same variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Getting next non missing value for the same variable

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.

Accepted Solutions
Solution
‎09-19-2013 07:22 AM
Contributor
Posts: 70

Re: Getting next non missing value for the same variable

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


All Replies
Respected Advisor
Posts: 4,644

Re: Getting next non missing value for the same variable

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
Occasional Contributor
Posts: 8

Re: Getting next non missing value for the same variable

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;

Solution
‎09-19-2013 07:22 AM
Contributor
Posts: 70

Re: Getting next non missing value for the same variable

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 201 views
  • 3 likes
  • 4 in conversation