sunshinegirl
sunshinegirl

Reputation: 81

How to make every row of a group match the final one in SAS

I am quite new to SAS and I would like to have the total for each group displayed in the final column.

I have tried this:

data appledata;
set apples;
by GroupID;
Total_Apples=max(Total_Apples);
run;

Unfortunately, there is no change when I tried this. Am I missing some kind of syntax?

Please find reprex of what I have below.

GroupID Number_of_Apples Total_Apples
1       .                0
1       5                5
1       .                5
1       8                13
2       2                2
3       4                4
3       1                5
3       1                6
4       2                2
4       .                2
5       .                0
5       0                0

I would like it to look like this:

GroupID Number_of_Apples Total_Apples
1       .                13
1       5                13
1       .                13
1       8                13
2       2                2
3       4                6
3       1                6
3       1                6
4       2                2
4       .                2
5       .                0
5       0                0

Any help would be appreciated, referencing the training or otherwise.

Upvotes: 0

Views: 30

Answers (1)

data _null_
data _null_

Reputation: 9109

You could do this. If you are going to use this technique you will need to learn to use IORC automatic variable. I did not need that here.

data apples;
   input GroupID Y;
   cards;
1       .                0
1       5                5
3       1                5
3       1                6
4       2                2
4       .                2
5       .                0
5       0                0
1       .                5
1       8                13
2       2                2
3       4                4

;;;;
proc print;
   run;
proc summary data=apples nway missing;
   class groupid;
   var y;
   output out=summary(index=(groupid)) n=n mean=mean max=max min=min;
   run; 
data apples2;
   set apples;
   set summary key=groupid/unique;
   run;
proc print;
   run;

Upvotes: 1

Related Questions