BookmarkSubscribeRSS Feed
jhem
Calcite | Level 5

Hi,

 

When using Proc Import to import a tab-delimited text file - how would I go on about ignoring the first 3 words of the file?

For example if I have a text file with the information:

"17JUN2020    09:10     STOCKHOLM     lab1    lab 2   lab 3

1   3   4"

then I would like to ignore the date, time and location and have lab1, lab2 and lab3 as column names with observations

1, 3 and 4.

 

Any thoughts?

 

/ Jesper

3 REPLIES 3
Kurt_Bremser
Super User

Your problem is this:


When using Proc Import

By using PROC IMPORT, you delegate thinking to the computer, and give up any control over the outcome.

Write your own data step instead.

How is your input file structured throughout? Do you always have the same words (lab1-lab3) in a line, followed by three values?

s_lassen
Meteorite | Level 14

I have not tested it, but it may be possible to simply put a DROP= or KEEP= dataset option on the output data set in PROC IMPORT. That way, the variables will still be read from the text file, but they will not be written to the output.

 

You could also, as suggested by @Kurt_Bremser, write your own data step code instead. After submitting PROC IMPORT, you can use a RECALL command (usually assigned to F4) in a SAS edit window to get the data step code that PROC IMPORT generated, and modify that. But as you will have to scan/read through the first 3 variables anyway to get to the stuff you want, there is probably not that much of a performance gain to this solution.

ballardw
Super User

@jhem wrote:

Hi,

 

When using Proc Import to import a tab-delimited text file - how would I go on about ignoring the first 3 words of the file?

For example if I have a text file with the information:

"17JUN2020    09:10     STOCKHOLM     lab1    lab 2   lab 3

1   3   4"

then I would like to ignore the date, time and location and have lab1, lab2 and lab3 as column names with observations

1, 3 and 4.

 

Any thoughts?

 

/ Jesper


Any one else here suspect that at some point in time there will be a request to look at that data as it changes over time or by location if more than one of these files exist?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 415 views
  • 0 likes
  • 4 in conversation