Hi:
I have to say that the answer is "it depends" -- what does your data look like?? Andy's solution assumed that your numbers were already fractions and
not multiplied by 100 (while your recent question shows the numbers as being multiplied by 100). There is a difference between:
[pre]
Andy:
proc format;
value tgt_pct_mask
0-.09999='Less than 10%'
.1-1=[percent7.1];
run;
Your question:
proc format;
value tgt_pct_mask 0-60='Less than 60%'
60-100=[percent6.2];
run;
[/pre]
While in my solution, the numbers WERE already multiplied by 100, so using the PERCENT format would not be appropriate. The PERCENT format does a multiply by 100. So without knowing what your data looks like, I can only say that you would NOT want to apply a PERCENT format to my example. From the doc:
"The PERCENTw.d format multiplies values by 100, formats them the same as the BESTw.d format, and adds a percent sign (%) to the end of the formatted value, while it encloses negative values in parentheses. "
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000205182.htm
Also, your width should be larger than 6.2, because (as it explains in the doc):
"The width of the output field must account for the percent sign (% ) and parentheses for negative numbers, whether the number is negative or positive."
At any rate, if you run the program below, I think you will see that it makes a BIG difference whether your number has already been multiplied by 100 or not.
cynthia
[pre]
proc format;
value tgt_pct_mask
0-<60='Less than 60%'
60 - high =[percent9.2];
value other low-<.6 = 'Less than 60%'
.6 - high =[percent9.2];
value agec 11-12 = 'Are Youngest'
13-14 = 'Can Babysit'
15-16 = 'Might Drive';
value $gend 'F' = 'Female'
'M' = 'Male';
run;
data calcpct;
set sashelp.class;
** PCT is already multiplied by 100;
pct = (height / weight) * 100;
** PCT2 is NOT multiplied by 100;
pct2 = (height/weight);
unfmt = pct2;
run;
ods listing;
proc report data=calcpct nowd ls=150 nocenter;
title 'Specify Formats Different Ways';
column age=agecat age name sex height weight pct pct2 unfmt;
define agecat / order f=agec.;
define name / order;
define age / order;
define sex /display 'Gender' f=$gend.;
define height / display;
define weight / display;
define pct / display f=tgt_pct_mask. 'PCT/Mult by 100/WRONG';
define pct2 / display f=other. 'PCT2 is fraction';
define unfmt / display 'No Format/Internal Value/for PCT2';
compute pct;
if pct gt 100 then call define(_col_,'format','6.2');
endcomp;
compute height;
if height le 59.99 then call define(_col_,'format','4.0');
else if height gt 60.00 then call define(_col_,'format','4.1');
endcomp;
run;
[/pre]