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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 680 views
  • 0 likes
  • 2 in conversation