BookmarkSubscribeRSS Feed
subrat1
Fluorite | Level 6
data yourdata;
   set yourdata;
   array change _numeric_;
        do over change;
            if change=. then change= NA;
        end;
 run ;

The above sas code does not work as i am trying to replace missing Numeric variable  value with NA

6 REPLIES 6
novinosrin
Tourmaline | Level 20

I think you would be better off using a user defined format to replace .=NA

 

subrat1
Fluorite | Level 6
Even after using user defined format .....The format of all numeric
variable changes....hence the data does not show correct value
Reeza
Super User

No, That's not how a user defined format works. Post your code if you're having issues. 

 


@subrat1 wrote:
Even after using user defined format .....The format of all numeric
variable changes....hence the data does not show correct value


 

 

Reeza
Super User

Well, a column is numeric or character and NA is a character. So you're trying to put a character in a field that expects a number. 

 

Do you need NA to export it to R? 

How are you exporting, perhaps modify it there?

 

What you're trying to do overall will define how this should be approached.

 

SuryaKiran
Meteorite | Level 14

Hi,

 

User defined format solves your problem. See below code

PROC FORMAT ;
PICTURE Num    .="NA"
             OTHER="00.00";
			 run;

data test;
input  Number ;
format Number num. ;
cards;
3.3
6.8
10
.
run;
Thanks,
Suryakiran
PGStats
Opal | Level 21

Defining your own numeric format is the simplest way to replace the printed values:

 

data test;
do x = 1, ., .a, ._, 2;
    output;
    end;
run;

proc format;
value myMiss
. = "          NA"
other = [best12.];
run;

proc datasets library=work nolist;
modify test;
format _numeric_ myMiss.;
run;

proc print data=test; run;

Note that special missing values are not affected by the custom format as defined above.

 

PG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 5946 views
  • 0 likes
  • 5 in conversation