Help using Base SAS procedures

Procprint with multiple #byvals and sum statemants

Reply
Frequent Contributor
Posts: 117

Procprint with multiple #byvals and sum statemants

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

Super User
Super User
Posts: 7,976

Re: Procprint with multiple #byvals and sum statemants

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;
Ask a Question
Discussion stats
  • 1 reply
  • 86 views
  • 0 likes
  • 2 in conversation