Help using Base SAS procedures

count question

Reply
Contributor
Posts: 22

count question

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.
Regular Contributor
Posts: 165

Re: count question

Sounds like you are looking for the RETAIN statement
Respected Advisor
Posts: 3,900

Re: count question

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;
PROC Star
Posts: 1,566

Re: count question

Maybe:

data T;
set T nobs=NOBS; *read nb of obs;
COUNT=NOBS; *save nb of obs;
run;
Ask a Question
Discussion stats
  • 3 replies
  • 136 views
  • 0 likes
  • 4 in conversation