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 ;
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
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
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 ;
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
Thanks ! That also works as intended.
Br.
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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.