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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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