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

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!

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.

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