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;
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;
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;
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;
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: