Gary Glasspool
Gary Glasspool

Reputation: 87

Row label is being truncated

I have written the following query to extract a list of distinct military status from a SAS table.

proc sql;
create table mil_stat as
    select distinct MILITARY_STAT_sERSS format $MILSTAT. as MILITARY_STATUS, 
        count(*) as TOTAL 
    from FPE
    group by MILITARY_STAT_sERSS;
quit;

I need to add a summary row that shows the total count. I tried to do this in the proc sql statement, but could not figure out how to do it. So, I wrote the following proc report statement to provide the needed row in the report.

PROC REPORT DATA=work.mil_stat;
column MILITARY_STATUS TOTAL;
where MILITARY_STATUS ne '5';
define MILITARY_STATUS / group;
rbreak after / summarize style=[font_weight=bold];
compute MILITARY_STATUS;
    if MILITARY_STATUS ne . then c_MILITARY_STATUS=MILITARY_STATUS;
    else c_MILITARY_STATUS=' ';
    if _break_ = '_RBREAK_' then MILITARY_STATUS = "Grand Total";
endcomp;
run;

The grand total row displays, but 'Grand Total' is truncated to a single character. Result table from proc report statement

Any assistance to be able to display the 'Grand Total' string would be much appreciated.

Upvotes: 1

Views: 550

Answers (2)

Joe
Joe

Reputation: 63424

Another solution would be to assign a value for the total ('G' is fine, or 'T', or whatever fits with your data) and then use that in the format. This would be my preferred solution, as it avoids having an unformatted value, and uses less space, but does require you to be able to adjust the format (or perhaps you can use a pass through format, if not).

proc format;
  value $sex
  'F' = 'Female'
  'M' = 'Male'
  'T' = 'Grand Total';
quit;

proc report data=sashelp.class;
columns sex height;
format sex $sex.;
define sex/group missing;
define height/analysis mean;
rbreak after/summarize;
compute sex;
    if _break_='_RBREAK_' then sex='Total';
endcomp;
run;

Upvotes: 0

Tom
Tom

Reputation: 51566

Looks like MILITARY_STAT_sERSS is only one byte long. And also the format, $MILSTAT., that you are using with that variable does not have any decode for 'G'.

Try making MILITARY_STATUS long enough to store "Grand Total".

select MILITARY_STAT_sERSS as MILITARY_STATUS length=11 format=$MILSTAT. 
...

Upvotes: 1

Related Questions