sasformatuser-defined

SAS: When using user defined formats, if there's not a match, "default value" is the unformatted input variable?


In SAS EG, I have a user defined format

value $MDC
'001' = '77'
'002' = '77 
...
'762' = '14' 
etc.

My data set has DRG_code string variables with values like '001' and '140'.

I was trying to create a new variable, with the below code.

MDC = put(DRG_code, $MDC.)

Only there are more values for the variable DRG_code in my data set, then specified in the user defined format file, $MDC.

For example, when the data set DRG_Code equals '140' this value does not exist in the user defined format, and for some reason the put statement is returning MDC = '14' (which should only be its value with the DRUG code is '762').

Is there a way to make sure my put statement only returns a value from the user defined format when a corresponding value is present?

Grateful for feedback.

Lori

I've tried using formatting like "length" to have my put statement return 3, which I thought would result in "140" instead of "14" and that didn't work.

value $MDC
'001' = '77'
'002' = '77 
...
'762' = '14' 

MDC = put(DRG_code, $MDC.)

Solution

  • I presume all the value mappings were $2 because that is what is used for an 'unfound' source value. In order to ensure the length of 'unfound' values, make sure one of the formatted values has trailing spaces filling out to length of longest unfound value.

    value $MDC
    '001' = '77     ' /* 7 characters, presuming no DRG_code exceeds 7 characters */
    '002' = '77'
    '762  = '14'