BookmarkSubscribeRSS Feed
gzr2mz39
Quartz | Level 8
I have three variables: location, a and b:
location a b
x 1 2
y 1 2

How do I add an observation to the variable location called total where a=2 (1+1) and b=4 (2+2) so that I have:
location a b
x 1 2
y 1 2
total 2 4

Essentially what I want to do is to add an observation named total to the location variable that has the sum of columns a and b.

Thank you.
6 REPLIES 6
RickM
Fluorite | Level 6
You could do something like:

data want;
set have end=eof;
c+a;
d+b;
output;
if eof then do;
location="Total";
a=c;
b=d;
output;
end;
drop c d;
run; Message was edited by: RickM
gzr2mz39
Quartz | Level 8
Thank you.
Ksharp
Super User
Hi.
Base on this situation, I think proc tabulate and proc report would be best choice.


Ksharp
Peter_C
Rhodochrosite | Level 12
how about a SUM statement on PROC PRINT ?
gzr2mz39
Quartz | Level 8
RickM posted what I was looking for.
The goal was to incorporate the total (for each column) into the dataset.
Thank you.
Ksharp
Super User
Hi.
Dear Peter.
Op want ' Total :......' .
I think proc print is difficult to print 'Total' ..


Ksharp

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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