Hello,
I want use data step to read a very large raw data with infile statement.
firstly I want to know how many rows in the file,if I only want to read the last records, I can use firstobs=n obs=n option but I need to know the value of n first.
Please help.
DATA read_last_obs;
INFILE raw1 FIRSTOBS=9999999 OBS=9999999.;
INPUT a $50.;
RUN;
Thanks!
I don't think so, reading in a text file is a linear process, its starts at character 1 and runs to the end of the file. Why can you not proces the data once its read in, even really big files shouldn't take that long? Why would you want only a few observations from the end?
Take a look at the END= INFILE option.
If you are working under Linux/Unix this can be done. But the exact statements are beyond my Unix knowledge. Here's the idea.
Unix contains a "tail" command that lists end of a file. Instead of listing it, the results can be piped to a file.
Now combine all of this with an INFILE statement. The INFILE statements contains the "tail" command, piping its results as part of the INFILE statement definition (rather than to a file). The combination lets the INFILE statement retrieve the tail end of the data source.
If you indicate that this would be useful for you, I'm sure someone on the board can give you more specific code.
I just want to get last row of record, this will save time and space if i know the total number of rows
Thanks!
Found a Unix command to count number of lines in a file:
wc -l filename
Are you working on Unix?
working on z/os
Thanks
DATA _null_;
INFILE '/folders/myfolders/all_jd.csv' end=last;
INPUT;
n+1;
if last then putlog 'NOTE: File have ' n ' rows.'/
'The last row is:' _infile_ ;
RUN;
Maybe you should take a look at the function relate to FILE, Like FGET(), FOPEN() ............. But I totally don't have any clue about it .
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.
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.