View previous topic :: View next topic
|
Author |
Message |
goran
New User
Joined: 27 Aug 2010 Posts: 2 Location: Chennai
|
|
|
|
Hi,
This is my first post to this forum and I tried searching my problem in other topics but couldn't find it.
I am very new to SAS programming and wrote few report creation program based on existing ones but I am facing a problem with a new one now.
My requirement is to read from 2nd last line if a particular string is found in the current file read pointer.
Is there any specific function/command in SAS if I can do it. Or need to read the file twice (first to calculate the required row then to fetch the line required ) Or is there any other easy way. I am looking into SAS manuals for sometime but if anyone can help I will be grateful.
Thanks,
goran |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
You can use the LAG1 function in SAS to hold an observation over to the next observation. So something like this should work for your need:
Code: |
DATA X;
INFILE DD01 END=EOF;
INPUT @001 DATALINE $CHAR<fill in length of record>;
HOLDLINE = LAG1(DATALINE) ;
<other logic>
IF EOF
THEN DO;
<HOLDLINE has the next-to-last line's data so use it as needed>
END;
|
|
|
Back to top |
|
|
goran
New User
Joined: 27 Aug 2010 Posts: 2 Location: Chennai
|
|
|
|
Hi Robert,
Thank you very much for the reply! what I understood is that LAG3 will be needed for this scenario..
Cheers,
goren |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
goran wrote: |
Hi Robert,
Thank you very much for the reply! what I understood is that LAG3 will be needed for this scenario..
Cheers,
goren |
well, I am sure that you have tested it,
so which one works, LAG1 or LAG3? |
|
Back to top |
|
|
|