BookmarkSubscribeRSS Feed
dennis_oz
Quartz | Level 8

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;

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

sureshsas
Calcite | Level 5

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.

Scott_Mitchell
Quartz | Level 8

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

ballardw
Super User

if name='Trailer' then stop;

stat_sas
Ammonite | Level 13

Try this.

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

..
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 1042 views
  • 0 likes
  • 6 in conversation