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

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 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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

 

 

View solution in original post

8 REPLIES 8
novinosrin
Tourmaline | Level 20
if anyalpha(calving_ease)>0 then call missing(calving_ease);
Barkamih
Pyrite | Level 9

this code has deleted the numeric numbers as well !! 

novinosrin
Tourmaline | Level 20

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

 

 

LinusH
Tourmaline | Level 20
Just input(), invalid numerical data will be missing automatically.
Data never sleeps
novinosrin
Tourmaline | Level 20

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

ballardw
Super User

@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.

Astounding
PROC Star

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;

novinosrin
Tourmaline | Level 20

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;

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 connect to databases in SAS Viya

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.

Discussion stats
  • 8 replies
  • 1728 views
  • 3 likes
  • 5 in conversation