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

Hi

How do I display a text "Subtotal of [sex]" in the age column in this example;

ods listing close ;

ods html;

proc report data=sashelp.class nowd;

  column sex age height;

  define sex / group  noprint ;

  compute before sex / style=[just=l fontweight=bold];

    text1=sex;

    line text1 $;

  endcomp;

  define age / group  ;

  compute age;

       if _break_='_RBREAK_' then do;

       call define("age", 'style', 'style=[pretext="Total "]');

       end;

  endcomp;

  define height / analysis SUM ;

  break after sex / summarize ;

  rbreak after / summarize;

  run;

ods html close; Run ;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Ou. You have changed the age from numeric to character.

If you allow this transformation ,that would very easy. I think you can do it better.

data test;
set sashelp.class;
age_text = put(age,10.);
run;

ods listing close ;
ods html file='c:\x.html';
options missing=' ';
proc report data=test nowd out=x;
column sex age_text height;
define sex / group noprint ;
define age_text / group missing ;
define height / analysis SUM ;
compute before sex ;
  age_text = sex;call missing(height.sum);
endcomp;
compute after sex;
  age_text = catx(' ',"subtotal",sex);
endcomp;
compute after ;
  age_text = "total";
endcomp;
break before sex / summarize ;
break after sex / summarize ;
rbreak after / summarize;
run;
Run ;
ods html close; 
ods listing;

Ksharp

View solution in original post

5 REPLIES 5
Ksharp
Super User

How about :

ods listing close ;
ods html;
proc report data=sashelp.class nowd;
  column sex age height;
  define sex / group  noprint ;
  compute after sex / style=[just=l fontweight=bold];
    text1='Subtotal of '||sex;
    line text1 $34. height.sum best10.;
  endcomp;
  compute after /style=[just=l fontweight=bold];
    text2='Total';
    line text2 $40. height.sum best10.;
  endcomp;
  define age / group  ;
  compute age;
       if _break_='_RBREAK_' then do;
       call define("age", 'style', 'style=[pretext="Total "]');
       end;
  endcomp;
  define height / analysis SUM ;
  run;

ods html close; 

Ksharp

SandSand
Fluorite | Level 6

Ksharp, thanks. Didn't seem to work as I wanted though. But found out:

data test;

set sashelp.class;

age_text = put(age,10.);

run;

ods listing close ;

ods html;

proc report data=test nowd;

column sex age_text height;

define sex / group noprint ;

compute before sex / style=[just=l fontweight=bold];

    text1=sex;

    line text1 $;

endcomp;

define age_text / group missing ;

define height / analysis SUM ;

break after sex / summarize ;

compute after sex;

  age_text = "subtotal";

endcomp;

rbreak after / summarize;

run;

quit;

ods html close; Run ;

Ksharp
Super User

Ou. You have changed the age from numeric to character.

If you allow this transformation ,that would very easy. I think you can do it better.

data test;
set sashelp.class;
age_text = put(age,10.);
run;

ods listing close ;
ods html file='c:\x.html';
options missing=' ';
proc report data=test nowd out=x;
column sex age_text height;
define sex / group noprint ;
define age_text / group missing ;
define height / analysis SUM ;
compute before sex ;
  age_text = sex;call missing(height.sum);
endcomp;
compute after sex;
  age_text = catx(' ',"subtotal",sex);
endcomp;
compute after ;
  age_text = "total";
endcomp;
break before sex / summarize ;
break after sex / summarize ;
rbreak after / summarize;
run;
Run ;
ods html close; 
ods listing;

Ksharp

SandSand
Fluorite | Level 6

Thanks ! That also works as intended.

Br.

Cynthia_sas
SAS Super FREQ

Hi:

  Another alternative is to use your PRETEXT technique for the report break and  as for the other breaks. The only difference is that you need to build your style= override string into a variable for the CALL DEFINE statement.

cynthia

ods listing close ;

ods html file='c:\temp\something.html' style=sasweb;

  

proc report data=sashelp.class nowd;

  column sex age height;

  define sex / group  noprint ;

  define age / group  style(column)={cellwidth=1in};

  define height / analysis SUM ;

  break after sex / summarize ;

  rbreak after / summarize;

   

  compute before sex / style=[just=l fontweight=bold];

    text1=sex;

    line text1 $5.;

  endcomp;

  

  compute age;

       length pt $20 sstr $50 text1 $1;

       if _break_='_RBREAK_' then do;

       call define("age", 'style', 'style=[pretext="Total "]');

       end;

       if upcase(_break_) = 'SEX' then do;

          pt= catx(' ', 'Subtotal of',text1);

          sstr = 'style=[pretext="'||trim(pt)||'"]';

          ** use temporary variable for value of style override;

          call define("age", 'style', sstr);

       end;

  endcomp;

  run;

   

ods html close;

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!

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
  • 5 replies
  • 4797 views
  • 0 likes
  • 3 in conversation