Help using Base SAS procedures

Need some info on proc format default values

Reply
Contributor
Posts: 40

Need some info on proc format default values

hello,

If we have defined proc format for a character variable and if in proc format if we have not defined other value, it will default to "NA", correct ?

But we wanted to output all values where it is NA after applying format, how to do this ?

For ex - put(compress(sex),$gender.)  if value from this function is NA, can we just output what ever value that came in for variable : sex ?

thanks!

Super User
Super User
Posts: 6,502

Need some info on proc format default values

If you have not defined an other category then the default is to echo the input.

proc format ;

  value $gender 'M'='Male' 'F'='Female' other='NA';

run;

Contributor
Posts: 40

Need some info on proc format default values

Actually I need something else, not the value NA.

Below code -

if  Trim(put(compress(sex),$gender.)) eq 'NA' then gend_code = sex;

          else gend_code= put(compress(sex),$gender.) ;

This is like sample code. I have something else actually with major percentage of records going to NA and for those records I wanted to input the value used in format originally with out using a lookuo value. In above case, when value = NA from put function, then use value in sex variable to gend_code.

Thanks!

Valued Guide
Posts: 2,175

Need some info on proc format default values

As Tom said, when you do not define an OTHER= range

the default is to echo the input

just beware that the default length on output is not the input length but the widest string you have defined in your user format (or the value you can define with

value $gender(default=5) 'M'='Male' 'F'='Female' other='NA';
Ask a Question
Discussion stats
  • 3 replies
  • 121 views
  • 0 likes
  • 3 in conversation