Help using Base SAS procedures

Add one observation (sample mean) to existing SAS dataset

Reply
Occasional Contributor
Posts: 15

Add one observation (sample mean) to existing SAS dataset

I want to add one more observation to the exisiting SAS dataset and could not find a good resolution ....

I have two variables called X,Y with 1000 observations each.

X represents categories (ranging from 0 to 1000 but numbers themselves have no meaning), and Y represents each category's score.

I want to add a 1001st row for X that denotes a category that does not appear between 0 and 1000, and assign it the value of sample average of 1000 Y values.

So the 1001st row will have: X = 9999, Y=sample average of Y's
Thank you!
Valued Guide
Posts: 632

Re: Add one observation (sample mean) to existing SAS dataset

There are multiple ways to do this. With your small data sets, a variation of the following should work for you.
[pre]proc summary data=sashelp.class;
var height;
output out=sumry mean=height;
run;

data extra(keep=name height);
set sashelp.class(keep=height name) end=eof;
output extra;
if eof then do;
name='Xxxxx';
set sumry;
output extra;
end;
run;[/pre]
Occasional Contributor
Posts: 15

Re: Add one observation (sample mean) to existing SAS dataset

Thank you!
Ask a Question
Discussion stats
  • 2 replies
  • 1075 views
  • 0 likes
  • 2 in conversation