Help using Base SAS procedures

Formatting single row based on parameter value

Reply
Regular Contributor
Regular Contributor
Posts: 170

Formatting single row based on parameter value

Hello all;
I am trying to format a single row apart from the others so that the calculated (CRBSI) rate has two decimal points in a 5.2 format while all other rows have a standard 5. format;
Been playing around with it, but to no avail...
The code:

format bwcat1-bwcat6 total 5.;
if _label_ ='CRBSI RATE' THEN DO;
format bwcat1-bwcat6 total 5.2 ;
End;

I understand what it is doing-when the variable name matches the if statement it reverts all the rows to the new format...I just don't how to specify...

Much thanks...

Lawrence
Super User
Posts: 5,426

Re: Formatting single row based on parameter value

The format statement is "global" for variables in the whole table, and a format cannot be assigned based on a row basis in table. Is _label_ a user defined variable? (showing your whole code make it easier for us to help you). If you like to set a certain format conditionally on the table level, you can use macro programming.

Regards,
Linus
Data never sleeps
Regular Contributor
Regular Contributor
Posts: 170

Re: Formatting single row based on parameter value

Linus;
I figured as much as to the fact that format is a "global statement"
_LABEL_ is generated as a byproduct of a proc transpose...
The whole code is quite lengthy and it is only this part that is causing a small obstacle.

I will take a stab at writing a macro perhaps...
Thank you for the clarity on this issue...

Lawrence
SAS Super FREQ
Posts: 8,864

Re: Formatting single row based on parameter value

Hi:
I think a macro approach would not be required, when PROC REPORT can do this easily for reporting purposes.

As far as the data set descriptor goes, the same format has to be applied to the same numeric column -- unless you turn the numeric variable into a character variable using the PUT function and different formats.

cynthia
[pre]
ods listing;
options nodate nonumber;
proc report data=sashelp.class nowd;
column name age height;
define name / order;
define age / f=8.0;
define height / f=8.0;
compute age;
if name = 'Barbara' then do;
call define (_col_,'format','8.3');
end;
else if name = 'John' then do;
call define (_col_,'format','8.5');
end;
endcomp;
compute height;
if name = 'Barbara' then do;
call define (_col_,'format','8.3');
end;
else if name = 'John' then do;
call define (_col_,'format','8.5');
end;
endcomp;
run;
[/pre]
Regular Contributor
Regular Contributor
Posts: 170

Re: Formatting single row based on parameter value

Posted in reply to Cynthia_sas
Cynthia;
Will certaintly give this a try!
Thank you!
Regular Contributor
Regular Contributor
Posts: 170

Re: Formatting single row based on parameter value

Cynthia;
Worked like a charm!
Thank you!

Lawrence
Ask a Question
Discussion stats
  • 5 replies
  • 103 views
  • 0 likes
  • 3 in conversation