BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
leehsin
Quartz | Level 8
Thank you, ChrisNZ !
If I had a extra line below the last line as a tail and I wanted to exclude it (different .txt files have different amount of the rows, so that we can't identify and use the row number to locate the tail for all .txt files), what will the code look like?
Kurt_Bremser
Super User

In the INFILE statement, use the end= option to define a flag variable; use this flag variable to not output the last line:

data _null_;
infile '/home/fkhurshed/Demo1/demo.txt.sas' end=done;
file "&work_path./temp.txt";
input ;
if _n_ < 4 or done then delete;
else put _infile_;
run;
ChrisNZ
Tourmaline | Level 20

Since you opted to using proc import, you don't have many ways to customise the way you read the file.

Your last row will have to be deleted manually, if proc import includes it.

 

data WANT;

  set WANT end=LASTOBS;

  if LASTOBS then delete;

 run;

 

When using the infile statement, there are many options, such as the one showed by @Kurt_Bremser .

 

leehsin
Quartz | Level 8

It can be accomplished now with my task of importing .TXT files with head lines and tail lines.

 

Thanks for everyone's help!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 18 replies
  • 13278 views
  • 5 likes
  • 8 in conversation