DATA Step, Macro, Functions and more

Missover is not giving exact answer`

Reply
New Contributor
Posts: 2

Missover is not giving exact answer`


data sid8;
infile datalines missover;
input name $ sex $ age city $ company $ ;
datalines;
Rahul 22 Banglore TCS
Mahesh M 26 Mumbai AXIS
Kiran 24 Pune CYTEL
swati F 26 Mumbai KOTAK
Mahesh M 23 Mumbai AXIS
;
run;

 

It is not assigning missing valuea as blank  to variable sex

Super User
Posts: 17,831

Re: Missover is not giving exact answer`

That's not how missover works, especially since you don't have delimiter to identify missing. 

 

SAS really can't know that 22 isn't a valid sex. 

New Contributor
Posts: 2

Re: Missover is not giving exact answer`

[ Edited ]

Then what is exact use of missover and how to use

Super User
Posts: 17,831

Re: Missover is not giving exact answer`

This is a well covered topic if you search here or the Internet. 

 

https://communities.sas.com/t5/Base-SAS-Programming/What-is-the-difference-between-Missover-and-Trun...

 

If if your data doesn't have specific delimiters besides a space your going to have a hard time reading in your file. 

Super Contributor
Posts: 305

Re: Missover is not giving exact answer`

it is hard to believe you don't have at least 2 consecutive delimiters between your variables in case, for example, sex is missing.

 

if the case adding dsd delimiter=' '; to your infile statement will do it.

Super User
Super User
Posts: 7,401

Re: Missover is not giving exact answer`

You would need to do this yourself.  There is no logical way to identify "2" as sex anymore than "M" or "F".  Consider using delimited data in future.

Post process example:

data sid8 (keep=name sex age city company);
  length name sex age city company str $40;
  infile datalines dlm="¬";
  input str $;
  name=scan(str,1," ");
  next=2;
  if scan(str,2," ") in ("M","F") then do;
    sex=scan(str,2," ");
    next=3;
  end;
  age=scan(str,next," ");
  next=next+1;
  city=scan(str,next," ");
  next=next+1;
  company=scan(str,next," ");
datalines;
Rahul 22 Banglore TCS
Mahesh M 26 Mumbai AXIS
Kiran 24 Pune CYTEL
swati F 26 Mumbai KOTAK
Mahesh M 23 Mumbai AXIS
;
run;
Super User
Posts: 10,500

Re: Missover is not giving exact answer`

What do you want the values of your other variables to be when "missing" the sex value?

Your current code gets missing values of age because it reads the city and city has the value of company.

If you actually have a lot of data of this poor quality you are going to have to parse the input string and treat the case of missing sex differently.

 

data sid8;
   infile datalines missover;
   input @ ;
   if upcase(scan(_infile_,2)) in ('M','F') then input name $ sex $ age city $ company $ ;
   else input name $  age city $ company ;
   datalines;
   Rahul 22 Banglore TCS
   Mahesh M 26 Mumbai AXIS
   Kiran 24 Pune CYTEL
   swati F 26 Mumbai KOTAK
   Mahesh M 23 Mumbai AXIS
   ;
run;

However it would be much preferabl to get the data layout in a better form such as suggested by @Loko or @RW9as the number of exceptions are likely to increase such imbedded spaces in names of people, cities or companies and varying number of name parts for people.

 

Ask a Question
Discussion stats
  • 6 replies
  • 254 views
  • 0 likes
  • 5 in conversation