BookmarkSubscribeRSS Feed
clambert22
Fluorite | Level 6

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;
5 REPLIES 5
RichardDeVen
Barite | Level 11
What does 'myData' look like ? Is variable day' numeric or character ?
RichardDeVen
Barite | Level 11

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

report.png

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
clambert22
Fluorite | Level 6

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;
ghosh
Barite | Level 11

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;

Untitled.png

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

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
  • 633 views
  • 0 likes
  • 4 in conversation