BookmarkSubscribeRSS Feed
sasbasls
Calcite | Level 5

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!

3 REPLIES 3
Tom
Super User Tom
Super User

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;

sasbasls
Calcite | Level 5

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!

Peter_C
Rhodochrosite | Level 12

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';

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 677 views
  • 0 likes
  • 3 in conversation