sas reading a blank record

Reply
Occasional Contributor
Posts: 14

sas reading a blank record

hi in my below file below is my file after trailer there is a (.)

So when i execute my data setep , it is telling 4 records have been read. the  record after trilaer is being read. I do not want to read that . Any suggestion

data a;

input name $;

if trailer then delete;

datalines;

aa

bb

cc

Tailer
..

run;

Super User
Super User
Posts: 7,988

Re: sas reading a blank record

Posted in reply to dennis_oz

Sorry, not really understanding you very well, you don't want any observations after/including the trailer one?  Why not just remove them from the datalines step?  You could add a retained flag:

data a;

input name $;

retain flag;

if _n_=1 then flag=0;

if trailer then flag=1;

if not flag then output;

datalines;

aa

bb

cc

Tailer
..

run;

The question is, why?

New Contributor
Posts: 4

Re: sas reading a blank record

Hi dennis ,

I am sorry not getting  your question  according to my understanding if there are trailing blanks

remove it by it by input options.

Super Contributor
Posts: 297

Re: sas reading a blank record

Posted in reply to dennis_oz

If '..' is not an acceptable value in any of the previous observations you could.use the following:

DATA A;

INPUT NAME $ @;

IF NAME = '..' THEN STOP;

DATALINES;

AA

BB

CC

TRAILER

..

;

RUN;

The trailing @ holds the input record so that you can process the item conditionally.  In this case we are telling SAS to stop processing once a '..' is read.

Alternately you could use:

DATA A;

INPUT NAME $ @;

IF NAME = '..' THEN DELETE;

DATALINES;

AA

BB

CC

TRAILER

..

RUN;

This will delete any occurrence of '..'.

I hope this helps.

Regards,

Scott

Super User
Posts: 11,343

Re: sas reading a blank record

Posted in reply to dennis_oz

if name='Trailer' then stop;

Trusted Advisor
Posts: 1,229

Re: sas reading a blank record

Posted in reply to dennis_oz

Try this.

data have;
input name $10.;
output;
if name eq 'Tailer' then stop;
datalines;
aa
bb
cc
Tailer

..
run;

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