Monday, August 28, 2006

Sas format

/************* to get out format********/

proc format lib=formats
cntlout=peulot ;
select $ origact;
run;

/********* to get in format *********/

proc format cntlin=ofi
lib=formats;
run;


/********** convert numeric to character*****/
new_char=put(numeric,4.0);
/********** convert character to numeric *****/
new_num=input(char4,best4.);


DATASTEP using a CNTLIN= option.The smaller file must not have any duplicates of the key variable used for matching. The DATASET created must have these elements:

FMTNAME: name of format to create
TYPE: ‘C’ for character or ‘N’ for numeric
START: the value you want to format into a label.

If you are specifying a range,
START specifies the lower end of the range and
END specifies the upper end.*/
LABEL: the label you wish to generate.*/


proc sort data=small
out=temp
nodupkey
force;
by seqnum;
data fmt (rename=(seqnum=start));
retain fmtname ‘$key’
type ‘C’
label ‘Y’;
set temp;
proc format cntlin=fmt;
run;
data _null_;
infile bigfile;
file extract;
if put(seqnum,$key.)=’Y’
then put _infile_ ;
run;
data match;
set bigfile;
if put(seqnum,$key.)=’Y’;
run;



proc format;
value score 370 - 670 = ‘670-‘
671 - 870 = ‘671+’
other = ‘unscored’
;
proc freq data=cb;
tables score;
format score score.;
run;


1. The name of the format does not have to be the
name of the variable that it will be assigned to.
2. The assignment of the FORMAT occurs in the
PROC with a FORMAT statement.
3.The format definition ends with the ‘;’ on a new line.



/***************GENERATING NEW VARIABLES WITH PROC
FORMAT AND A VALUE REPLACEMENT FORMAT
SPECIFYING RANGES IN PROC FORMAT
*********/



proc format;
value edr low-159 = ’53.4’
160-169 = ’39.3’
170-179 = ’32.3’
180-high = ’25.8’
;
data stuff;
set cb2;
edr=input(put(score,edr.),4.1);
run;


Ranges can include intervals such as:
. means that the interval includes
both endpoints.
<- . means that the interval
includes higher endpoint, but not the lower
one.
- < means that the interval
includes lower endpoint, but not the higher
one.
<- < means that the interval
does not include either endpoint.
3. The numeric “ . “ and character ‘ “ “ ‘ missing
values can be individually assigned values.
4. Ranges can be specified with special kewords:
LOW From the least (most negative) possible
number.
HIGH To the largest (positve) possible number.
OTHER All other numbers not otherwise
specified.
5. The LOW keyword does not format missing values.
6. The OTHER keyword does include missing values
unless accounted for with a ‘.’ or ‘ ‘.*/;


SAS PICTURE FORMATS
SAS PICTURE Formats provide a template for
printing numbers .
To use the saved format in a subsequent program
without having to enter the FORMAT code, specify a
LIBNAME of LIBRARY referencing the library .


One example of using PICTURE FORMATS is to truncate numbers that represents dates from
YYMMDD display to YY/MM.
proc format;
picture dt 0-991231=’11/11’
(multiplier=.01);
run;

The ‘11/11’ specifies that all leading zeros will be displayed.
If the label was ‘01/11’ then 001213 would
be displayed as 0/12 instead of 00/12.


will print a leading 0 if the percentage is less than 1
(i.e., .67% displays as 0.67%).
proc format;
picture p8r (round)
0-100 = '0009.99%'
run;

No comments: