Hi There,
i few sample data placed in datalines, I just wanted to skip those lines which has got "name" and "age" values,
i just wanted to read only real data.
I tried this below code, but it's not cool, I am looking for some better options, like #N or / options to skip certain lines, but
I do not know how to use above tools?
data have;
input value $ @;
if value eq "name" then delete;
else; input name $ age;
drop value;
datalines;
name age
Dharmu 20
Vivian 18
name age
Tina 20
Kath 21
name age
John 30
Tim 30
;
run;
Thanks!!
If you are positive of the pattern (one garbage line followed by two good lines), you can use:
data have;
input / name $ age;
output;
input name $ age;
output;
datalines;
name age
Dharmu 20
Vivian 18
name age
Tina 20
Kath 21
name age
John 30
Tim 30
;
But if you don't know the pattern ahead of time, there's no way for you to tell SAS the pattern (through your programming statements) ahead of time.
What's not to like about what you have? I think it's cool enough.
A shorter alternative would be:
data have;
input name $ @;
if value eq "name" then delete;
else; input age;
datalines;
name age
Dharmu 20
Vivian 18
name age
Tina 20
Kath 21
name age
John 30
Tim 30
;
run;
By the way, your original code has an issue. Be aware that if you hold the input record with a trailing '@' the pointer will not be at the beginning of the record for the next input statement. You will have to reset it:
...
else input @1 name $ age;
...
Hope this helps,
- Jan.
Yes Thanks, I figured it out when saw the output, thanks for pointing that out,
but can we use those line pointer to skip the lines, I mean just curius to learn that.
@LittlesasMaster wrote:
but can we use those line pointer to skip the lines, I mean just curius to learn that.
Yes you can. Use the forward slash in your INPUT statement. Or simply use another INPUT statement.
- Jan
I would do:
data have;
input @;
if _infile_ eq "name age" then input;
else do;
input name $ age;
output;
end;
datalines;
name age
Dharmu 20
Vivian 18
name age
Tina 20
Kath 21
name age
John 30
Tim 30
;
If you are positive of the pattern (one garbage line followed by two good lines), you can use:
data have;
input / name $ age;
output;
input name $ age;
output;
datalines;
name age
Dharmu 20
Vivian 18
name age
Tina 20
Kath 21
name age
John 30
Tim 30
;
But if you don't know the pattern ahead of time, there's no way for you to tell SAS the pattern (through your programming statements) ahead of time.
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.