BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

In the following data I need to calculte a sum value for a few OBS.

 

For my data I need to calculate a total value for trt in (15,30,37).

 

data have;
input ns trt $ trtc $;
datalines;
20 15 A
30 30 B
10 37 C
50 Place D
;


output needed;

20 15 A
30 30 B
10 37 C
50 Place D
60 Total E
;



2 REPLIES 2
Shmuel
Garnet | Level 18

Try code:

 

proc print data=have(where=(trt in (15,30,37)));

    var ns trt trtc;

    sum ns;

run;

Astounding
PROC Star

To get a data set that matches your output goal:

 

data want;

set have end=done;

if trt in ('15', '30', '37') then tot_ns + ns;

output;

if done;

ns = tot_ns;

trt='Total';

trtc='E';

output;

drop tot_ns;

run;

 

It's ready for PROC PRINT or whatever you decide the next step should be.

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
  • 2 replies
  • 724 views
  • 2 likes
  • 3 in conversation