## Fill out matrix / data set according to a pattern.

Solved
Super Contributor
Posts: 355

# Fill out matrix / data set according to a pattern.

Hello!

I'd like to fill out a data set by 'a group'. The rule is, that if a column has a value within a group, its value should be filled in - forward AND backward.

The start data is:

Data Have;

Input N \$ X1-X4;

Datalines;

A 1 . . .

A 1 . . .

A 1 . . .

A . 2 . .

A . 2 . .

B 1 . . .

B 1 . . .

B . . 3 .

B . . . 4

B . . . 4

C . 2 . .

C . 2 . .

C . . 3 .

;

Run;

The end data should be:

A 1 2 . .

A 1 2 . .

A 1 2 . .

A 1 2 . .

A 1 2 . .

B 1 . 3 4

B 1 . 3 4

B 1 . 3 4

B 1 . 3 4

B 1 . 3 4

C . 2 3 .

C . 2 3 .

C . 2 3 .

Thanks&kind regards

Accepted Solutions
Solution
‎10-22-2014 11:30 AM
Posts: 1,270

## Re: Fill out matrix / data set according to a pattern.

Data Have;
infile datalines missover;
Input N \$ X1-X4;
Datalines;
A 1 . . .
A 1 . . .
A 1 . . .
A . 2 . .
A . 2 . .
B 1 . . .
B 1 . . .
B . . 3 .
B . . . 4
B . . . 4
C . 2 . .
C . 2 . .
C . . 3 .
;
Run;

proc stdize data=have reponly out=want;
var x1-x4;
by n;
run;

All Replies
Super User
Posts: 13,584

## Re: Fill out matrix / data set according to a pattern.

Is it at all possible that for any group any of the Xi could have 2 or more non-missing values? If so, what would the rule be?

Super Contributor
Posts: 355

## Re: Fill out matrix / data set according to a pattern.

Sorry ballardw, I didn't answer your question. You're right, there are at least 2 non-missing values. I need this a an intermediate result for a 'look-up' table (and hope I will finally get to my desired result).

Solution
‎10-22-2014 11:30 AM
Posts: 1,270

## Re: Fill out matrix / data set according to a pattern.

Data Have;
infile datalines missover;
Input N \$ X1-X4;
Datalines;
A 1 . . .
A 1 . . .
A 1 . . .
A . 2 . .
A . 2 . .
B 1 . . .
B 1 . . .
B . . 3 .
B . . . 4
B . . . 4
C . 2 . .
C . 2 . .
C . . 3 .
;
Run;

proc stdize data=have reponly out=want;
var x1-x4;
by n;
run;

Posts: 3,852

## Re: Fill out matrix / data set according to a pattern.

Do you know how to get rid of those warnings?  Update can in this case produce the same result without being warned unnecessary.

data want2;
do _n_ = 1 by 1 until(last.n);
update have(obs=0) have;
by n;
end;

do _n_ = 1 to _n_;
output;

end;

run;
Posts: 1,270

## Re: Fill out matrix / data set according to a pattern.

Thanks for your input. As always, a very smart suggested solution. As far as I know warning messages are generated  becasue proc stdize uses location and scale parmaters to standardize/impute missing values. These statisticas are computed whatever is available within a variable. If all of the values are missing withing a variable/group then it will not be possible to calculate these statistics so as a result these messages are appearing in the log. I am not sure how to get rid of those and looking forward to have some suggestions from the forum regarding this.

Posts: 3,852

## Re: Fill out matrix / data set according to a pattern.

I really like "all things STDIZE" but I don't want those warnings.

🔒 This topic is solved and locked.