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
;
Try code:
proc print data=have(where=(trt in (15,30,37)));
var ns trt trtc;
sum ns;
run;
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.