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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register 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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 696 views
  • 0 likes
  • 4 in conversation