I am trying to fill in the value "Total" into the Day column on the report summary line in this PROC REPORT step but I can't get the value to populate. There are no errors in my log but I can't get the value to populate. What am I missing? (Thanks in advance for your help!)
proc report data = mydata;
columns day n pct;
define day / group "Day";
define n / "Count";
define pct / "Percent" computed f=percent9.1;
compute before;
Total = n;
endcomp;
compute pct;
pct = n/Total;
endcomp;
rbreak after / summarize;
compute after;
day="Total";
endcomp;
run;
Presuming the data set has a single numeric column day
.
Because day
is numeric you can not assign it a character value 'Total'
for the summary line.
Change the report definition to have an additional computed column of type character, call it dayx
, that is assigned from the day
column. dayx
will need it's own empty compute block in order to set it's type as character. A compute block can only access columns to the left of itself, so dayx
will be before day
. Also day
will be /NOPRINT
so it does not appear in the report.
Example:
data have(keep=day);
call streaminit(123);
do day = 1 to 10;
do seq = 1 to 10 + rand('integer',1,10);
output;
end;
end;
run;
ods html file='report.html' style=plateau;
proc report data = have;
columns dayx day n pct;
define dayx / "Day" computed;
define day / group "Day" noprint;
define n / "Count";
define pct / "Percent" computed f=percent9.1;
compute before;
Total = n;
endcomp;
compute pct;
if not missing(Total) then pct = n / Total;
endcomp;
rbreak after / summarize;
compute dayx / character length=5;
endcomp;
compute day;
dayx = ifc ( missing (day), 'Total', cats(day) );
endcomp;
run;
ods html close;
Output
@RichardDeVen wrote:
Because
day
is numeric you can not assign it a character value'Total'
for the summary line.
But you can assign a format to DAY so that the word Total appears as needed.
Argh! Thanks for catching the character/numeric column mix up.
So I tried assigning a numeric value instead and then laying a format over it but it's still not populating. 😕 I've used this approach before in other reports so confused as to why it is not working here.
proc format;
value myday
1 = "Sunday"
2 = "Monday"
3 = "Tuesday"
4 = "Wednesday"
5 = "Thursday"
6 = "Friday"
7 = "Saturday"
8 = "Total"
;
run;
proc report data = mydata;
columns Day n pct;
define Day / group order=internal f=myday.;
define n / "Count";
define pct / "Percent" computed f=percent9.1;
compute before;
Total = n;
endcomp;
compute pct;
pct = n/Total;
endcomp;
rbreak after / summarize;
compute after;
Day = 8;
endcomp;
run;
Just guessing what your data looks like:
data mydata;
do n=1 to 7;
day=put(n+1, downame.);
output;
end;
run;
proc report data=mydata;
columns Day n, (Sum pctsum);
define Day / group 'Day' order=data;
define n / "My table label" sum;
define Sum / "Count";
define pctsum / "Percent" f=percent9.1;
rbreak after / summarize;
compute after;
Day='Total';
endcomp;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: