BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MicheleB0108
Calcite | Level 5

I am trying to replace the NA values for 0 in the 5 markdown variables. The first time, I tried using the method from one of these other community message, and it worked. I took down notes and tried it again and now it isn't working. Instead what it's doing is creating a new variable field "NA" with no values in it. I attached pictures of the import data resulting from the code I'm using. I have little to no experience coding so it may be something relatively obvious! I'm using the University Edition, Basic 3.8.

 

DATA work.import;
	set work.import;
	array change _character_;
		do over change;
		if change=NA then change=0;
		end;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Please try the below code, I guess the NA need to be in quotes also the 0 as the 5 variables are character.

 

 

DATA work.import;
	set work.import;
	array change _character_;
		do over change;
		if change='NA' then change='0';
		end;
run;
Thanks,
Jag

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Please try the below code, I guess the NA need to be in quotes also the 0 as the 5 variables are character.

 

 

DATA work.import;
	set work.import;
	array change _character_;
		do over change;
		if change='NA' then change='0';
		end;
run;
Thanks,
Jag
gamotte
Rhodochrosite | Level 12

Hello,

 

Are your variables really of character nature or did the import make them character because

of "NA" observations ?

 

If your variables are numeric then use numeric columns to store them.

 

You can use an informat to interpret "NA" as missing values or zeros :

 

proc format;
    invalue mynum
        'NA'=0;
run;

data have;
    informat x mynum.;
    input x;
    cards;
1
2
NA
5
NA
3
;
run;
PaigeMiller
Diamond | Level 26

Adding on to the excellent advice by @gamotte, you might be better served as keeping NA as missing rather than numeric zero, which can screw up averages and any other statistics you want to compute.

 

proc format;
    invalue mynum 'NA'=.;
run;
--
Paige Miller

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 6281 views
  • 1 like
  • 4 in conversation