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-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
  • 5681 views
  • 1 like
  • 4 in conversation