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
dharmu | 25 | 40000 |
john | . | 450000 |
dharmu | 25 | 40001 |
dharmu | 25 | 40002 |
25 | 40003 | . |
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;
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:
You get the idea but it will be a bit messy.
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;
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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.