Data
data lb; length lbtest $40; lbtest='Hematocrit'; output; lbtest='Leukocytes'; output; lbtest='HDL Cholesterol/Total Cholesterol'; output; run;
![]() |
Program
proc format; value $lbtest 'Hematocrit' ='HCT' 'Leukocytes' ='WBC' 'HDL Cholesterol'='HDL'; value $lbtestcd 'HCT'='Hematocrit' 'WBC'='Leukocytes' 'HDL'='HDL Cholesterol'; run; data lb_new; set lb; length lbtestcd $40; lbtestcd=put(lbtest,$lbtest.); run;
![]() |
The variable lbtestcd
is created using the variable lbtest
and the format $lbtest.
The goal is to get the short name of the laboratory test from the long one.
Hematocrit
becomesHCT
Leukocytes
becomesWBC
- The value "
HDL Cholesterol/Total Cholesterol
" is not in format$lbtest.
. It becomes "HDL
" which has a different meaning. According to$lbtestcd.
format, it meansHDL Cholesterol
.
a) Task
Display the width and the default width of the format label $lbtest.
- Using the fmtlib option
- By saving format details in a dataset.
b) Question
Why "HDL Cholesterol/Total Cholesterol
" becomes "HDL
"?
c) Task
Update the program in order to display the full test name in the variable lbtestcd
when no match is available in the format.
- Change the default format label width when creating the format, or
- Change the format label width given in the put function
![]() |
![]() |
Before |
After |
d) Task
Update the program in order to display the text "To Check
" when no match is available in the format.
![]() |
![]() |
Before |
After |