Hi
Calving_ease
1
2
3
1
1
2
NA
2
NA
5
2
4
NA
NA
1
2
2
1
I would like to convert this variable records(CHARACTERS) to missing data instead of NA. as well as I want to keep the same variable name(Calving_ease) in my original dataset (MFD4)
Regards
No it hasn't in the sample you provided, below is my test and log
data have;
input Calving_ease $;
datalines;
1
2
3
1
1
2
NA
2
NA
5
2
4
NA
NA
1
2
2
1
;
data want;
set have;
if anyalpha(calving_ease)>0 then call missing(calving_ease);
run;
436
437 data have;
438 input Calving_ease $;
439 datalines;
NOTE: The data set WORK.HAVE has 18 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
458 ;
459
460 data want;
461 set have;
462 if anyalpha(calving_ease) then call missing(calving_ease);
463 run;
NOTE: There were 18 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 18 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.00 seconds
if anyalpha(calving_ease)>0 then call missing(calving_ease);
this code has deleted the numeric numbers as well !!
No it hasn't in the sample you provided, below is my test and log
data have;
input Calving_ease $;
datalines;
1
2
3
1
1
2
NA
2
NA
5
2
4
NA
NA
1
2
2
1
;
data want;
set have;
if anyalpha(calving_ease)>0 then call missing(calving_ease);
run;
436
437 data have;
438 input Calving_ease $;
439 datalines;
NOTE: The data set WORK.HAVE has 18 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
458 ;
459
460 data want;
461 set have;
462 if anyalpha(calving_ease) then call missing(calving_ease);
463 run;
NOTE: There were 18 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 18 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.00 seconds
I agree with @LinusH however you may need to add a ?? modifier to prevent sas from writing NOTE: Invalid data for Calving_ease in line . messages in the log
@novinosrin wrote:
I agree with @LinusH however you may need to add a ?? modifier to prevent sas from writing NOTE: Invalid data for Calving_ease in line . messages in the log
Or use a custom informat to assign a special missing for the N/A values. That way you know the source of the data was specifically marked N/A.
To keep the same name, you have to add a little tap dancing:
data want;
set have;
tempvar = input(calving_ease, ??8.);
drop calving_ease;
rename tempvar = calving_ease;
run;
Compress seems to work too:)
data have;
input Calving_ease $;
datalines;
1
2
3
1
1
2
NA
2
NA
5
2
4
NA
NA
1
2
2
1
;
data want;
set have;
calving_ease=compress(calving_ease,,'kd');
run;
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!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.