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;   
If you have set up the score-grade mapping already:
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.
This will help you determine the boundary value, 
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;  

Related links:
Continue to: Automation for Data Exploring in data mining   SAS tutorial home
Back to: How to format Excel file by SAS DDE?   Statistics tutorial home