Fill out matrix / data set according to a pattern.

Accepted Solution Solved
Reply
Super Contributor
Posts: 336
Accepted Solution

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
Trusted Advisor
Posts: 1,203

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;

View solution in original post


All Replies
Grand Advisor
Posts: 10,210

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: 336

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
Trusted Advisor
Posts: 1,203

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;

Respected Advisor
Posts: 3,775

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;
Trusted Advisor
Posts: 1,203

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.

Respected Advisor
Posts: 3,775

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.

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

Discussion stats
  • 6 replies
  • 232 views
  • 3 likes
  • 4 in conversation