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