BookmarkSubscribeRSS Feed
Hart
Calcite | Level 5
I have done this function before but am frustrated that I can not remember how!

so I have a table with 68k observations. I would like to create a new column in my dataset with this total number. I do not wish to hardcode this number because it may change.

currently my dataset is:

N N_tot T_tot
0 68243 47739
1 376 182
2 204 144
3 427 248
4 217 150
5 575 326
6 87 62
7 393 247
8 1096 710
9 453 296

I would like to appear as

N N_tot T_tot Count
0 68243 47739 68243
1 376 182 68243
2 204 144 68243
3 427 248 68243
4 217 150 68243
5 575 326 68243
6 87 62 68243
7 393 247 68243
8 1096 710 68243
9 453 296 68243

I would really appreciate any assistance.
3 REPLIES 3
RickM
Fluorite | Level 6
Sounds like you are looking for the RETAIN statement
Patrick
Opal | Level 21
In case that the N_tot value in row one is not always the one containing the maximum then the following would be an option:

data have;
input N N_tot T_tot;
datalines;
0 68243 47739
1 376 182
2 204 144
3 427 248
4 217 150
5 575 326
6 87 62
7 393 247
8 1096 710
9 453 296
;
proc sql;
/*create table want as*/
select *,max(n_tot) as Count
from have;
quit;
ChrisNZ
Tourmaline | Level 20
Maybe:

data T;
set T nobs=NOBS; *read nb of obs;
COUNT=NOBS; *save nb of obs;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1161 views
  • 0 likes
  • 4 in conversation