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
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?
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.
@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?
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!
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.