different decimal places for different laboratory tests pharmasug 2004, tt01 a. cecilia mauldin

34
Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Upload: angelica-pope

Post on 29-Dec-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Different Decimal Places For Different Laboratory TestsPharmaSug 2004, TT01A. Cecilia Mauldin

Page 2: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

What is a Lab?What can be a problem?Different ways of solving the problem

The data for these examplesThe PUTN function

When should we be carefulCalculating the width and number of decimal places

The variable that is formatting is calculatedCreating a table of laboratory results

Final thoughtsReferences

Different Decimal Places for Different Lab Tests

Page 3: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

What is a Lab?Laboratory Test

Laboratory Result

HCT 35.36

35.046

PLT 118.045

118.666

118.111

RDW 16.16

17.166

12.1666

12.16666

WBC 4.0

10.005

Page 4: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

What is a lab?

A Lab Mix

Page 5: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

What Can Be a Problem?

When reporting results for listings, we do not need to format. We should present the data as it is received.

Unless we want to present all the lab results from the same test with the same format

But when doing tables, how many decimals should each laboratory test have for the mean? For the standard deviation?

Page 6: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Different Ways of Solving the Problem

Every Lab test will use the same format

All will have best. or best.2?All will have 10.2

We put as many “IF” statements as there are Lab testsWe use select statementsWe use a macro variable for each test…

Page 7: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Different Ways of Solving the Problem

We Use the values from a modified version of the LabNormal dataset or another dataset where the width and number of decimal places for each test is given and use the PUTN function.

Page 8: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

The Modified LabNormal Dataset

Lab Test

Low Normal Value

High Normal Values

Created Format

HCT 30.0 40.0 5.2

PLT 100.0 130.0 5.0

RDW 15.0 20.0 5.2

WBC 7.0 15.0 7.4

Page 9: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

The Data for this Examples

data new; input LAB $ result @@ ; cards; HCT 35.36 HCT 35.046 PLT 118.045 PLT 118.111 PLT 118.666 RDW 16.16 RDW 17.166 RDW 12.1666 RDW 12.16666 WBC 4.0 WBC 10.005 ;run;

data useinfor;input lab $ frstf $

lowhigh

@@;cards; HCT 5.1 30 40 PLT 5.0 100 130 RDW 5.2 15 20 WBC 7.4 7 15;run;

Page 10: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

The Data for this Examples

(both datasets were already sorted by lab);

data toprint; merge new useinfor; by lab;run;

proc print data=toprint; by lab; id lab;run;

Page 11: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

LAB result frstf low high

HCT 35.360 5.1 30 40 35.046 5.1 30 40PLT 118.045 5.0 100 130

118.111 5.0 100 130 118.666 5.0 100 130

RDW 16.160 5.2 15 20 17.166 5.2 15 20 12.167 5.2 15 20 12.167 5.2 15 20

WBC 4.000 7.4 7 15 10.005 7.4 7 15

The Data for this Examples

We did not select a format for the RESULT variable. SAS is using 7.3 (or 22.3) as the best way to print the results.

Page 12: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

The PUTN Function

title "Using PUTN with a format variable that already exists";

data firste; set toprint;

formatm = putn( result , frstf);

label formatm="FORMATM: value with format given by FRSTF"

;

run;

Page 13: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

The PUTN Function

Using PUTN with a format variable that already exists

FORMATM: value with format given LAB result frstf by FRSTF

HCT 35.360 5.1 35.4 35.046 5.1 35.0

PLT 118.045 5.0 118 118.111 5.0 118 118.666 5.0 119

RDW 16.160 5.2 16.16 17.166 5.2 17.17 12.167 5.2 12.17 12.167 5.2 12.17

WBC 4.000 7.4 4.0000 10.005 7.4 10.0050

Page 14: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

The PUTN Function

The PUTN Function’s structure is:

NewVar=PUTN(Nres, FMT, width1, deci);

Where:

NRES is an existing Numeric Variable. In this example RESULT.

FMT is an existing Character variable. In this example FRSTF.

It has to be character because values that are acceptable are date., ddmmyy10., time5. …

WIDTH1 is an Optional Numeric variable with final width of NewVar.

DECI is an Optional Numeric variable with number of decimals included in NewVar

Page 15: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

The Variable That Is Formatting Is Calculated

The format of the output variable can depend on the value of the numeric result.

If the result is smaller than the Normal Lower Limit (NLL) we will increase the number of decimals, if the result is bigger than the Normal Upper Limit (NUL) we will increase the width.

Page 16: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

The Variable That Is Formatting Is Calculated

title2 "Second Example";title3 "the variable that is formatting is calculated";

data seconde; set toprint;

if result< low then meanf=putn(result,put(input(frstf,best.) + 0.1,best.));

else if result>high then meanf=putn(result,put(input(frstf,best.) + 1.0,best.));

run;

Page 17: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

The Variable That Is Formatting Is Calculated

Second Example the variable that is formating is calculated

LAB result low high frstf meanf

HCT 35.360 30 40 5.1 35.4 35.046 30 40 5.1 35.0

PLT 118.045 100 130 5.0 118 118.111 100 130 5.0 118 118.666 100 130 5.0 119

Smaller than the LLV

RDW 16.160 15 20 5.2 16.16 17.166 15 20 5.2 17.17 12.167 15 20 5.2 12.17 12.167 15 20 5.2 12.17

WBC 4.000 7 15 7.4 4.00000 10.005 7 15 7.4 10.0050

If you want to show 3 decimal places for 12.167, you need to have 6.3

Did you mean to round?

Who decided rounding for you?

Page 18: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

When representing data:

Find the maximum number of decimals in each lab test.

Decide Rounding and number of decimal presented depending in the number of decimals in your data.

Page 19: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Creating a Table of Lab Results

The table that we want has:

The Laboratory Lab Test,

The Mean and Standard deviation for each test.

The Mean is going to have one more decimal place than the maximum number of decimals reported by the lab.

Page 20: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Creating a Table of Lab Results

• The Standard Deviation is going to have two more decimal places than the maximum number of decimals reported by the lab.

Page 21: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Creating a Table of Lab Results

Rounding should be done before any formatting takes place.

This will help search for values with too many decimals or not enough decimal values.

Time for an advertisement for Proc SQL.

Page 22: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Calculating the Width and Number of Decimal Places

PROC SQL;

CREATE TABLE LABS AS SELECT DISTINCT

LAB, result, PUT(result,BEST.) AS CHAR FROM new ORDER BY lab ;

The dataset LABS has the new variable CHAR, from where we can search for a decimal place and we can calculate the number of decimal places in each observation.

CHAR HAS ALL THE DECIMAL PLACES IN RESULT.

Page 23: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Calculating the Width and Number of Decimal Places

PROC SQL; CREATE TABLE DECIMAL AS SELECT DISTINCT LAB, MAX(LENGTH(CHAR)-

INDEX(CHAR,'.')) AS DECIMAL FROM LABS WHERE CHAR LIKE '%.%' GROUP BY LAB ;

SELECT * FROM DECIMAL;

The dataset Decimal is the equivalent of our LabNormal dataset, there is one record for each Lab test with the maximum number of decimals for that test

Page 24: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Calculating the Width and Number of Decimal Places

The Variable that will format is calculated

LAB DECIMAL HCT 3 PLT 3 RDW 5 WBC 3

Page 25: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Calculating the Width and Number of Decimal Places

CREATE TABLE DECIMAL AS SELECTDISTINCTLAB,DECIMAL,10**(-DECIMAL -1) FORMAT BEST. AS ONERND,10**(-DECIMAL -2) FORMAT BEST. AS TWORND,"32." ||PUT(DECIMAL +1,1.) AS ONEFMT,"32." ||PUT(DECIMAL +2,1.) AS TWOFMTFROM DECIMAL;

SELECT * FROM DECIMAL;QUIT;

Page 26: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Calculating the Width and Number of Decimal Places

OneFMT is the value that has the maximum number of decimals plus one for each lab test.

OneRnd is the value that has the number of decimals needed to round to one more decimal than the maximum number of decimals for each lab.

TwoFMT is the value that has the maximum number of decimals plus one for each lab test.

TwoRnd is the value that has the number of decimals needed to round to two more decimal than the maximum number of decimals for each lab.

Page 27: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Calculating the Width and Number of Decimal Places

the variable that is formatting is calculated

LAB DECIMAL ONERND TWORND ONEFMT TWOFMT

HCT 3 0.0001 0.00001 32.4 32.5PLT 3 0.0001 0.00001 32.4 32.5RDW 5 1E-6 1E-7 32.6 32.7WBC 3 0.0001 0.00001 32.4 32.5

Page 28: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

The everyday job…

PROC UNIVARIATE DATA=LABS NOPRINT; VAR RESULT; BY lab; OUTPUT OUT=STAT MEAN=MEAN STD=STD;RUN;

DATA FORMATED; MERGE STAT DECIMAL; BY LAB; RMEAN=ROUND(MEAN,ONERND); FMEAN=PUTN(RMEAN,ONEFMT); FSTD=PUTN(ROUND(STD,TWORND), TWOFMT);RUN;

Page 29: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

The end!

LAB MEAN STD DECIMAL RMEAN FMEAN FSTD

HCT 35.203 0.22203 3 35.203 35.2030 0.22203PLT 118.274 0.34108 3 118.274 118.2740 0.34108RDW 14.415 2.62827 5 14.415 14.414815 2.6282669WBC 7.003 4.24618 3 7.003 7.0025 4.24618

Rmean: the rounded mean. SAS is choosing the format for me. All the Labs have the same format.

Fmean: the formatted, rounded mean. I chose the format and the rounding.

FSTD: the formatted, rounded standard deviation

Page 30: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Final Thoughts

This presentation focuses in using the PUTN function but the method that should be used will depend on the kind of job that will be done. Factors that should be considered are:

Do you need do have different formats for different lab testsHow many different Laboratory tests are going to be reported.How many statistics are required.Do you need to round.

If yes, I would round first and then format.

Page 31: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Final Thoughts

If you calculate the width and maximum number of decimal places, you will

do a quick review of the data.get a handy tool to give the number of decimals.most of the time, just use 32 as the width. In this case, more is more.

Page 32: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

References

SAS Technical Report P-222. Changes and Enhancements to Base SAS Software. Release 6.07

Page 33: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Thank YOU for being here!

Also Thanks to:

Jim Nezamis for teaching me the PUTN function.

LaTonya Murphy, Lan Tran and Terry Strader for reviewing my presentation.

Bonnie Duncan and Kim Sturgen for their encouragement.

Page 34: Different Decimal Places For Different Laboratory Tests PharmaSug 2004, TT01 A. Cecilia Mauldin

Contact Information

This was a Power Pointer Mix Presentation

A.Cecilia Mauldin

3900 Paramount Parkway

Morrisville, NC 27560

Voice: (919)462-4199

[email protected]