EZ Study

Actuarial Biology Chemistry Economics Calculators Confucius Engineer
Physics
C.S.

Use put function to get the actual format value
Question: As statistician, sometimes we need to apply some particular format to get corresponding output: e.g. we usually have grade for score range: 90-100 for "A", 80-90 for "B", 70-80 for "C"... What's the easiest way to get the corresponding grade if I have a score?

Answer: Here is some sample code:
```data scale;
input begin \$ 1-2 finish \$ 5-8 amount \$ 10-12;
datalines;
0   3    0%
4   6    3%
7   8    6%
9   10   8%
11  16   10%
;
data ctrl;
length label \$ 11;
set scale(rename=(begin=start finish=end amount=label)) end=last;
retain fmtname 'PercentageFormat' type 'n';
output;
if last then do;
hlo='O';
label='***ERROR***';
output;
end;
run;
proc print data=ctrl noobs;
title 'The CTRL Data Set';
run;   ```
90-100 "A"
80-90 "B"
70-80 "C"
...
then you can load that file into SAS:
```%macro format(data,formatname1,formatname2);
proc import datafile="directory\&data."
out=v0     dbms=dlm     replace;
delimiter='09'x;  * used tab as delimiter;
datarow=2;
run;

data format_&formatname2.;
set v0 ;
retain fmtname "&formatname1." type 'n' EEXCL 'N';
EEXCL: End value excluded; SEXCL: Start value exclude.
Otherwise, by default, it will include the end value. ```
```output;
run;

proc format lib=work cntlin=format_&formatname2.;
run;
%mend format;

%format(PCNT_var1,var1_format,var1);   ```
You can use the following for testing:
```data example;
do i=-100 to 100 by 2;
var=i;
var_range=put(abs(var),var1_format.);
output;
end;
drop i;
run;  ```