DATA Step, Macro, Functions and more

How do i read missing values in middle and start using List Input style

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

How do i read missing values in middle and start using List Input style

[ Edited ]

I just wanted to read this data only using List input style ....I am not able to read it?

 

I tried this..

 

data test;
infile datalines missover;
input name $ age sal;
cards;
dharmu 25 40000
john   450000
dharmu 26 40001
dharmu 25 40002
      25 40003
;
run;
proc print;run;

 

output-

SAS Output

Obs name age sal 1 2 3 4 5
dharmu2540000
john.450000
dharmu2540001
dharmu2540002
2540003

.

 

 


Accepted Solutions
Solution
‎06-18-2016 09:25 AM
PROC Star
Posts: 1,759

Re: How do i read missing values in middle and start using List Input style

Posted in reply to Dharmendra_All_

Like this?

 


data WANT;
  infile datalines ;
  input;
  SCAN=1;
  if _infile_ ne: ' ' then do;
    NAME=scan(_infile_,1);
    SCAN+1;
  end;
  if 1 <= input(scan(_infile_,SCAN),3.) <= 120 then do;
    AGE=input(scan(_infile_,SCAN),3.) ;
    SCAN+1;
  end;
  SAL=input(scan(_infile_,SCAN),8.) ;
cards;
dharmu 25 40000
john   450000
peter 26 40001
Sue 25 40002
      25 40003
      25 40003
      25 
;
run;

View solution in original post


All Replies
Respected Advisor
Posts: 3,799

Re: How do i read missing values in middle and start using List Input style

Posted in reply to Dharmendra_All_

You need to use the period as a place holder for missing values in midde and start.  MISSOVER will handle missing at the end but you can as mark those as well.

 

If your data cannot be modified you will have to come up with a scheme that allows you to figure which field is missing.  

 

For example:

  • 2 fields and the first is numeric implies field 1 is missing
  • 2 fields and the first is char and second is numeric and out of age range implies field 2 is missing

You get the idea but it will be a bit messy.

 

Solution
‎06-18-2016 09:25 AM
PROC Star
Posts: 1,759

Re: How do i read missing values in middle and start using List Input style

Posted in reply to Dharmendra_All_

Like this?

 


data WANT;
  infile datalines ;
  input;
  SCAN=1;
  if _infile_ ne: ' ' then do;
    NAME=scan(_infile_,1);
    SCAN+1;
  end;
  if 1 <= input(scan(_infile_,SCAN),3.) <= 120 then do;
    AGE=input(scan(_infile_,SCAN),3.) ;
    SCAN+1;
  end;
  SAL=input(scan(_infile_,SCAN),8.) ;
cards;
dharmu 25 40000
john   450000
peter 26 40001
Sue 25 40002
      25 40003
      25 40003
      25 
;
run;
New Contributor
Posts: 2

Re: How do i read missing values in middle and start using List Input style

Thank you so much....

I am getting the right data but still I will try to understand the code...

being new into the system this code is complex to me but this is what I expected to.

 

Thanks!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 255 views
  • 1 like
  • 3 in conversation