BookmarkSubscribeRSS Feed
mcook
Quartz | Level 8

Given the following code and output.  I am trying to remove the lines circled in pink, and add the lines marked in blue ( though the added lines should be black). I've left the ID variable in just as a reference. 

 

the commented section in the compute weight block is one of the many things i've tried to add the line. But It does not seem to register 'Total' as an element of Name.  

 

data ClassTable;
	set SASHELP.Class;
	Section="A";
run;

data ClassTable1;
	set SASHelp.Class;
	Section="B";
run;

data ClassTable;
	set ClassTable ClassTable1;
run;

proc sql noprint undo_policy=none;
	delete from ClassTable
		where Name like '%J%' and Section="B";
quit;

proc sort data=ClassTable;
	by Sex Name Section;
run;

data ClassTable;
	set ClassTable;
	by sex name;

	if last.Name=0 then
		ID=1;

	if (last.Name=1) AND (First.Name=1) then
		ID=1;

	if (Last.Name=0) AND (First.Name=0) then
		ID=0;
run;

ods RTF file="&FilePath.\RowRemove.RTF";
ods escapechar='^';
options nonumber nodate;

proc report data=classtable spanrows
	style(report)=[rules=cols frame=hsides]
	style(Header)=[borderleftwidth=0.1pt borderleftcolor=black
	borderrightwidth=0.1pt borderrightcolor=black
	borderbottomwidth=0.1pt borderbottomcolor=black]
	style(Column)=[VJust=C];
	columns ID sex Name Weight;
	define ID / display;
	define sex / display group center
		style(Column)=[borderbottomwidth=0.1pt borderbottomcolor=black
		bordertopwidth=0.1pt bordertopcolor=black];
	define name / display group center format=$25.
		style(Column)=[borderbottomwidth=0.1pt borderbottomcolor=black
		bordertopwidth=0.1pt bordertopcolor=black cellwidth=1.5in];
	define Weight / analysis center;
	break after sex / summarize suppress style=[font_style=roman font_Weight=bold];

	compute after sex;
		Name='Total';
	endcomp;

	Compute Weight;
		call define(_Col_,'style','style=[fontweight=light]');

		if ID=1 then
			call define(_col_,'style','style=[bordertopwidth=0.1pt bordertopcolor=black]');

/*		if Name="Total" then*/
/*			call define(_col_,'style','style=[bordertopwidth=0.1pt bordertopcolor=black]');*/
	EndComp;
run;

ods rtf close;

 

InkedCapture_LI.jpg

 

4 REPLIES 4
Ksharp
Super User

You need make a TOTAL row by SQL or data step, NOT get it by BREAK AFTER.

 

data ClassTable;
	set SASHELP.Class;
	Section="A";
run;

data ClassTable1;
	set SASHelp.Class;
	Section="B";
run;

data ClassTable;
	set ClassTable ClassTable1;
run;

proc sql noprint undo_policy=none;
	delete from ClassTable
		where Name like '%J%' and Section="B";
quit;

proc sort data=ClassTable;
	by Sex Name Section;
run;

data ClassTable;
	set ClassTable;
	by sex name;

	if last.Name=0 then
		ID=1;

	if (last.Name=1) AND (First.Name=1) then
		ID=1;

	if (Last.Name=0) AND (First.Name=0) then
		ID=0;
run;




proc sql;
create table want as
select 1 as a,* from ClassTable 
union
select 2 as a,'Total',sex,
sum(age) as age,
sum(height) as height,
sum(weight) as weight
from ClassTable where id is not missing group by sex

order by sex,a;
quit;






ods RTF file="c:\temp\RowRemove2.RTF" bodytitle ;
ods escapechar='^';
options nonumber nodate;

proc report data=want spanrows
	style(report)=[rules=cols frame=hsides]
	style(Header)=[borderleftwidth=0.1pt borderleftcolor=black
	borderrightwidth=0.1pt borderrightcolor=black
	borderbottomwidth=0.1pt borderbottomcolor=black]
	style(Column)=[VJust=C];
	columns ID sex a Name Weight;
	define ID / display;
	define sex / display group center
		style(Column)=[borderbottomwidth=0.1pt borderbottomcolor=black
		bordertopwidth=0.1pt bordertopcolor=black];
	define a/order noprint;
	define name /  group center format=$25.
		style(Column)=[borderbottomwidth=0.1pt borderbottomcolor=black
		bordertopwidth=0.1pt bordertopcolor=black cellwidth=1.5in];
	define Weight / display center;
/*	break after sex / summarize suppress style=[font_style=roman font_Weight=bold];

	compute after sex;
		Name='Total';
	endcomp;*/

	Compute weight;
		call define(_Col_,'style','style=[fontweight=light]');

		if ID=1 then
			call define(_col_,'style','style=[bordertopwidth=0.1pt bordertopcolor=black]');

		if ID=. then
			call define(_col_,'style','style=[borderbottomwidth=0.1pt borderbottomcolor=black]');

/*		if Name="Total" then */
/*			call define(_col_,'style','style=[bordertopwidth=0.1pt bordertopcolor=black]');*/
	EndComp;
run;

ods rtf close;

Ksharp_0-1634909944900.png

 

mcook
Quartz | Level 8

Yeah, that is what I had originally done. But was just hoping to figure out a way to put the total into the report step.  Maybe its just not meant to be. 

Ksharp
Super User

OK . If you really need put TOTOAL in proc report. Try this one :

 

data ClassTable;
	set SASHELP.Class;
	Section="A";
run;

data ClassTable1;
	set SASHelp.Class;
	Section="B";
run;

data ClassTable;
	set ClassTable ClassTable1;
run;

proc sql noprint undo_policy=none;
	delete from ClassTable
		where Name like '%J%' and Section="B";
quit;

proc sort data=ClassTable;
	by Sex Name Section;
run;

data ClassTable;
	set ClassTable;
	by sex name;

	if last.Name=0 then
		ID=1;

	if (last.Name=1) AND (First.Name=1) then
		ID=1;

	if (Last.Name=0) AND (First.Name=0) then
		ID=0;
run;

ods RTF file="c:\temp\RowRemove2.RTF" bodytitle;
ods escapechar='^';
options nonumber nodate;

proc report data=classtable spanrows out=x
	style(report)=[rules=cols frame=hsides]
	style(Header)=[borderleftwidth=0.1pt borderleftcolor=black
	borderrightwidth=0.1pt borderrightcolor=black
	borderbottomwidth=0.1pt borderbottomcolor=black]
	style(Column)=[VJust=C];
	columns ID sex Name Weight;
	define ID / display;
	define sex /  group center
		style(Column)=[borderbottomwidth=0.1pt borderbottomcolor=black
		bordertopwidth=0.1pt bordertopcolor=black];
	define name /  group center format=$25.
		style(Column)=[borderbottomwidth=0.1pt borderbottomcolor=black
		bordertopwidth=0.1pt bordertopcolor=black cellwidth=1.5in];
	define Weight / analysis center;
	break after sex / summarize suppress style=[font_style=roman font_Weight=bold];

	compute after sex;
		Name='Total';
	call define('sex','style','style=[borderbottomwidth=0.1pt borderbottomcolor=black
 bordertopwidth=0.1pt bordertopcolor=white]');
 	call define('weight.sum','style','style=[bordertopwidth=0.1pt bordertopcolor=black]');
	endcomp;

	Compute Weight;
		call define(_Col_,'style','style=[fontweight=light]');

		if ID=1 then
			call define(_col_,'style','style=[bordertopwidth=0.1pt bordertopcolor=black]');

		call define('sex','style','style=[borderbottomwidth=0.1pt borderbottomcolor=white 
 bordertopwidth=0.1pt bordertopcolor=white]');

/*		if _break_='Sex' then*/
/*			call define('sex','style','style=[borderbottomwidth=2px borderbottomcolor=black*/
/*bordertopwidth=0.1pt bordertopcolor=white]');*/
	EndComp;
run;

ods rtf close;

Ksharp_0-1634983596566.png

 

Ksharp
Super User

Or this one:

 

data ClassTable;
	set SASHELP.Class;
	Section="A";
run;

data ClassTable1;
	set SASHelp.Class;
	Section="B";
run;

data ClassTable;
	set ClassTable ClassTable1;
run;

proc sql noprint undo_policy=none;
	delete from ClassTable
		where Name like '%J%' and Section="B";
quit;

proc sort data=ClassTable;
	by Sex Name Section;
run;

data ClassTable;
	set ClassTable;
	by sex name;

	if last.Name=0 then
		ID=1;

	if (last.Name=1) AND (First.Name=1) then
		ID=1;

	if (Last.Name=0) AND (First.Name=0) then
		ID=0;
run;

ods RTF file="c:\temp\RowRemove2.RTF" bodytitle;
ods escapechar='^';
options nonumber nodate;

proc report data=classtable spanrows out=x
	style(report)=[rules=cols frame=hsides]
	style(Header)=[borderleftwidth=0.1pt borderleftcolor=black
	borderrightwidth=0.1pt borderrightcolor=black
	borderbottomwidth=0.1pt borderbottomcolor=black]
	style(Column)=[VJust=C];
	columns ID sex Name Weight;
	define ID / display;
	define sex /  group center
		style(Column)=[borderbottomwidth=0.1pt borderbottomcolor=black
		bordertopwidth=0.1pt bordertopcolor=black];
	define name /  group center format=$25.
		style(Column)=[borderbottomwidth=0.1pt borderbottomcolor=black
		bordertopwidth=0.1pt bordertopcolor=black cellwidth=1.5in];
	define Weight / analysis center;
	break after sex / summarize suppress style=[font_style=roman font_Weight=bold];

	compute after sex;
		Name='Total';
	call define('sex','style','style=[borderbottomwidth=2 borderbottomcolor=black
 bordertopwidth=2 bordertopcolor=white]');
 	call define('weight.sum','style','style=[bordertopwidth=0.1pt bordertopcolor=black]');
	endcomp;

	Compute Weight;
		call define(_Col_,'style','style=[fontweight=light]');

		if ID=1 then
			call define(_col_,'style','style=[bordertopwidth=0.1pt bordertopcolor=black]');

/*		call define('sex','style','style=[borderbottomwidth=0.1pt borderbottomcolor=white */
/* bordertopwidth=0.1pt bordertopcolor=white]');*/

/*		if _break_='Sex' then*/
/*			call define('sex','style','style=[borderbottomwidth=2px borderbottomcolor=black*/
/*bordertopwidth=0.1pt bordertopcolor=white]');*/
	EndComp;
run;

ods rtf close;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 664 views
  • 0 likes
  • 2 in conversation