BookmarkSubscribeRSS Feed
sanjay1
Obsidian | Level 7

Hi Sas Experts,

 

Am summing marks1 and marks2 by using multiple byvals, and am getting the totals as two times.

I don't want to see the repeating totals, Please help.

Here is my code:


data new;
input name$ name1$ marks1 marks2;
datalines;
abc1 abc 20 30
abc1 abc 40 10
abc2 abc 40 10
abc2 abc 40 10
bca1 bca 30 45
bca1 bca 26 28
bca2 bca 30 45
bca2 bca 26 28
run;


options nobyline;
ods pdf file="path.pdf" startpage=no;
ods pdf startpage= bygroup;
title1 j=l "SAME -- #byval2";
proc print data=new noobs
sumlabel='Total' grandtotal_label='grand Total';
by name name1;
sum marks1 marks2;
title2 '^{newline 2}EACH-- @ #byval1';
run;
title1;

ods pdf close;

 

 

Kind regrads,

Sanjay

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

As with anything like this, I always do manipulations outside the reporting procedure.  This keeps your dataset having everything needed (good for validation) and the reporting procedure simple (good for coding).  Plus you can manipulate things anyway you like then.

data new;
  input name $ name1 $ marks1 marks2;
datalines;
abc1 abc 20 30
abc1 abc 40 10
abc2 abc 40 10
abc2 abc 40 10
bca1 bca 30 45
bca1 bca 26 28
bca2 bca 30 45
bca2 bca 26 28
;
run;

data new (drop=name_sum);
  set new;
  by name;
  retain name_sum;
  if first.name then name_sum=0;
  name_sum=sum(name_sum,marks1);
  if not(last.name) then output;
  else do;
    output;
    name="Sum";
    marks1=name_sum;
    output;
  end;
run;

proc print data=new;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 661 views
  • 0 likes
  • 2 in conversation