11-13-2012 03:00 PM
Is there a way to define a format that keeps a variable as numeric type but displays a character string much like the dollarw.d or percentw.d format?
For example, if the value stored is "1234.56" but is linked to format dollar7.2, then the value will appear as "$1,234.56" (technically a character string due to '$' and ',' but still numeric). Or if the value stored is "0.1234" and is linked to format percent9.1, then the value will appear as "12.3%" (technically a character string due to '%' but still numeric).
Now, if I have a numeric valued stored as "1.23" with a user-defined format, can I make it appear as "1.23 mg/m2" and still retain the numeric properties? I used to create a character variable by using: charvar=compress(numvar) || ' mg/m2'; but I want to retain the properties of a numeric variable so I can sort numerically and/or summarize the data while automatically displaying any units that should be attached.
11-13-2012 03:11 PM
Picture formats let you do such things as add suffix or prefixes to numbers using a combination of digit selectors and directives. The example below comes close. Use of 'mg/m2' treats the 2 as a digit selector and replaces the 2 with a 0, or possibly another digit depending on range of the numeric involved.
proc format library=work;
low-high = '000009.99 mg/msq';
put x mg.;
Need further help from the community? Please ask a new question.