Generating Value Statements Using PROC FORMAT

by Irina 21. May 2007 09:21
 /****************************************************************/
 /*          S A S   S A M P L E   L I B R A R Y                 */
 /*                                                              */
 /*    NAME: FORMAT                                              */
 /*   TITLE: Generating Value Statements Using PROC FORMAT       */
 /****************************************************************/
 
DATA _NULL_;
   FILE PRINT;
   PUT 'PROC FORMAT IS BEING GENERATED BY MACRO PROCESSOR_SEE SASLOG';
RUN;

%MACRO FORMAT(VAL=VAL,LOW=,START=,STOP=,COUNT=);

PROC FORMAT;
   VALUE &VAL
%DO X=&START %TO &STOP %BY &COUNT;
   &LOW-&X="&LOW-&X"
   %LET LOW=%EVAL(&X+1);
   %END;
         ;
%MEND FORMAT;

%FORMAT(LOW=18,START=20,STOP=75,COUNT=5) ;

DATA NEXT;
   INPUT VALUE;
   CARDS;
18
20
56
27
30
36
66
12
75
100
;


PROC PRINT;
   FORMAT VALUE VAL.;
RUN;

Tags: formats

SAS

CREATING MULTI-LABEL FORMATS

by Irina 8. May 2007 13:28

Multi-label formats can be used in PROC SUMMARY and PROC TABULATE.PROC FORMAT with its new MULTILABEL option could make overlapping.

Some comments on this format:

1. Note that we must specify the (multilabel) option when generating the format.
2. We can preserve the order of formatted values on tabulate output by specifying the NOTSORTED option
in the generation of the FORMAT and PRELOADFMT ORDER=DATA options
; the CLASS specification in TABULATE.
3. Note that we have labels for each of the 5 decision codes. We also map all codes beginning with the
letter
a into APPROVE TOTALS and all those beginning with the letter d into DECLINE TOTALS
4. The CLASS statement in TABULATE or SUMMARY ( 􀀆 ) must include the MLF option to generate the

Example1.(proc means)

data f;
input
Obs  name $ age;
cards;
1 mary 10
2 fred 28
3 john 7
4 erica 29
5 tim 5
6 susan 13
7 andrew 47
8 peter 37
9 cindy 16
10 thea 21
11 joe 20
12 tilly 58
13 ruth 75
14 rick 8
15 richard 19
16 helen 26
17 alexa 10
18 heather 2
;
run;
proc format;
value mlf1_fmt(multilabel)
0-12='child'
13-19='adolescent'
0-19='children and adolescents'
20-21='young adult'
low-21='children,adolescents and young adults'
22-high='all adults'
low-high='all patients';
run;


ods listing close;
ods rtf file='c:\result.rtf' bodytitle style=journal;
proc means data=f mean  median maxdec=2;
format age mlf1_fmt.;
class age /mlf order=data preloadfmt;
var age;
run;
ods rtf close;
ods listing;


proc format;
value mlf2_fmt(multilabel notsorted)
0-12='child'
13-19='adolescent'
0-19='children and adolescents'
20-21='young adult'
low-21='children,adolescents and young adults'
22-high='all adults'
low-high='all patients';
run;

ods listing close;
ods rtf file='c:\result1.rtf' bodytitle style=journal;
proc means data=f mean  median maxdec=2;
format age mlf2_fmt.;
class age /mlf order=data preloadfmt;
var age;
run;
ods rtf close;
ods listing;

Example2.(proc tabulate)

proc format;
value key low - 0.20 = 'a1'
0.20 < - 0.25 = 'a2'
0.25 < - 0.35 = 'a4'
0.35 < - 0.80 = 'd1'
0.80 < - high = 'd6'
;
picture p8r (round)
low - < 0 = '0009.99%' (prefix='-')
0 - high = '0009.99%'
;
value $deccode (multilabel notsorted) ..
'a0' - 'a9' = 'APPROVE TOTALS'
'a1' = ' a1: Approval'
'a2' = ' a2: Weak Approval'
'a4' = ' a4: Approved Alternate Product'
'd0' - 'd9' = 'DECLINE TOTALS'
'd1' = ' d1: Decline for Credit'
'd6' = ' d6: Decline Other'
run;
data decision;
do id = 1 to 1000;
decision = put(ranuni(7),key.);
output;
end;
run;
proc tabulate data=decision noseps formchar=' ';
class decision/mlf preloadfmt order=data;
format decision $deccode.;
table (decision all)
,n*f=comma5.
pctn='%'*f=p8r.
/rts=33 row=float misstext=' ';
run;

 

About the author

Irina Spivak Irina Spivak
Team Leader at G-Stat. More...


Send mail Email

Authors

Blogroll

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010

    Sign in

    eXTReMe Tracker