## User-Defined Numeric Formats

Solved
Regular Contributor
Posts: 247

# User-Defined Numeric Formats

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.

Accepted Solutions
Solution
‎11-13-2012 03:04 PM
PROC Star
Posts: 8,164

## Re: User-Defined Numeric Formats

You could always create a picture format.  Take a look at: http://www2.sas.com/proceedings/sugi31/243-31.pdf

All Replies
Solution
‎11-13-2012 03:04 PM
PROC Star
Posts: 8,164

## Re: User-Defined Numeric Formats

You could always create a picture format.  Take a look at: http://www2.sas.com/proceedings/sugi31/243-31.pdf

Regular Contributor
Posts: 247

## Re: User-Defined Numeric Formats

I knew there would be something simple in PROC FORMAT, but I wasn't finding it.  This did the trick.  Thanks!

Super User
Posts: 13,542

## Re: User-Defined Numeric Formats

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;

🔒 This topic is solved and locked.