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

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!!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

6 REPLIES 6
jklaverstijn
Rhodochrosite | Level 12

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;

jklaverstijn
Rhodochrosite | Level 12

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.

LittlesasMaster
Obsidian | Level 7

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.

 

jklaverstijn
Rhodochrosite | Level 12

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

 

See http://support.sas.com/documentation/cdl/en/basess/68381/HTML/default/viewer.htm#p0s16wvzu0z9q7n0zmx...

 

- Jan

PGStats
Opal | Level 21

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
;
PG
Astounding
PROC Star

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.

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 4171 views
  • 3 likes
  • 4 in conversation