BookmarkSubscribeRSS Feed
SAS_user_n
Calcite | Level 5
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!
2 REPLIES 2
ArtC
Rhodochrosite | Level 12
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]

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore 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
  • 2 replies
  • 3123 views
  • 0 likes
  • 2 in conversation