BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kumarK
Quartz | Level 8

Hi I have the data like below. I want to calculate the total with in the group without considering that corresponding value.

if you take G3: for t8 after removing t8 value then the group total is : 1250,  like that i want all the combinations sum.

Is there any macro required here? can you please give some thoughts how can we proceed on this task. Thanks in advance.

data groups;

input group$ subg$ marks;

cards;

G1 t1 500

G1 t2 300

G1 t3 400

G1 t4 100

G2 t5 600

G2 t6 400

G2 t7 200

G3 t8 650

G3 t9 800

G3 t10 450

run;

i want output as:

GroupSub GMarkstotal
G1t1500800
G1t23001000
G1t3400900
G1t41001200
G2t5600600
G2t6400800
G2t72001000
G3t86501250
G3t98001100
G3t104501450
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use a SQL summation and then subtract the row value.

data groups;

input group$ subg$ marks;

cards;

G1 t1 500

G1 t2 300

G1 t3 400

G1 t4 100

G2 t5 600

G2 t6 400

G2 t7 200

G3 t8 650

G3 t9 800

G3 t10 450

run;

proc sql;

create table want as

select group, subg, marks, sum(marks)-marks as total

from groups

group by group

order by group, subg;

quit;

proc print data=want;

run;

View solution in original post

2 REPLIES 2
Reeza
Super User

Use a SQL summation and then subtract the row value.

data groups;

input group$ subg$ marks;

cards;

G1 t1 500

G1 t2 300

G1 t3 400

G1 t4 100

G2 t5 600

G2 t6 400

G2 t7 200

G3 t8 650

G3 t9 800

G3 t10 450

run;

proc sql;

create table want as

select group, subg, marks, sum(marks)-marks as total

from groups

group by group

order by group, subg;

quit;

proc print data=want;

run;

kumarK
Quartz | Level 8

Thank You ReeZa. You always rocks.:)

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
  • 899 views
  • 0 likes
  • 2 in conversation