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.
You could always create a picture format. Take a look at: http://www2.sas.com/proceedings/sugi31/243-31.pdf
You could always create a picture format. Take a look at: http://www2.sas.com/proceedings/sugi31/243-31.pdf
I knew there would be something simple in PROC FORMAT, but I wasn't finding it. This did the trick. Thanks!
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;
picture mg
low-high = '000009.99 mg/msq';
run;
data _null_;
x=1.23;
put x mg.;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: