BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
magicdj
Obsidian | Level 7

i set up some missing value as below.  in my excel output, i want the non missing numbers still the numbers, but for missing values , i want it show as NA. is there any way to do it? thanks

 

 

data Have;
Set sashelp.class;
if age=11 then age=.;

run;

proc export data=Have
outfile="/usr/local/SAS/SASUsers/LabRet.excel"
dbms=tab
label
replace;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why? What extra information does that add?

 

You could define a format that does that.

proc format;
  value na . = 'NA' other=[best12.];
run;

data test;
  set sashelp.class(obs=1);
  do age=age,.,._,.A,.Z ;
    output;
  end;
run;

proc print data=test;
  format age na.;
run;

Result

Obs     Name     Sex        Age         Height    Weight

 1     Alfred     M               14      69       112.5
 2     Alfred     M     NA                69       112.5
 3     Alfred     M                _      69       112.5
 4     Alfred     M                A      69       112.5
 5     Alfred     M                Z      69       112.5

If you want the other 27 missing values to also print as NA then define the format like this instead:

value na ._-.Z = 'NA' other=[best12.];

Or 

value na low-high=[best12.] other='NA';

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Why? What extra information does that add?

 

You could define a format that does that.

proc format;
  value na . = 'NA' other=[best12.];
run;

data test;
  set sashelp.class(obs=1);
  do age=age,.,._,.A,.Z ;
    output;
  end;
run;

proc print data=test;
  format age na.;
run;

Result

Obs     Name     Sex        Age         Height    Weight

 1     Alfred     M               14      69       112.5
 2     Alfred     M     NA                69       112.5
 3     Alfred     M                _      69       112.5
 4     Alfred     M                A      69       112.5
 5     Alfred     M                Z      69       112.5

If you want the other 27 missing values to also print as NA then define the format like this instead:

value na ._-.Z = 'NA' other=[best12.];

Or 

value na low-high=[best12.] other='NA';
magicdj
Obsidian | Level 7

hi, Tom the sas dataset show NA, ut when i export to excel. the result is not show. don't know what happened.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

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
  • 503 views
  • 0 likes
  • 2 in conversation