BookmarkSubscribeRSS Feed
rkumar23
Calcite | Level 5

I have data in the raw file as below

********************  TOD=180316  DATE=00115127  NAME=RECYCLE DATA SET ENDED  

     FUNC=RECYCLE MIG VOLUME      TOVOL=E36229  FRVOL=E32423  DEVT=78048081  ST

Now what I am doing with the below code is find FUNC=RECYLCE and then create the variable however while creating the variable I also need the DATE which means I need to go to previous record in the same DATA Step...I see certain ways but haven't come to the conclusion could somebody point please...

DATA OUT01;                                                            

   RETAIN   ;                                                          

   INFILE   HSMLOG;                                                    

   INPUT    @001    HSMLOG       $120. ;                               

   INDX1A = INDEX(HSMLOG,'FUNC=RECYCLE');                              

IF INDX1A GT 0 THEN DO;                                                

      PUT HSMLOG;                                                      

      TOVOL     = SUBSTR(HSMLOG,36,6);                                 

      FRVOL     = SUBSTR(HSMLOG,50,6);                                 

      STARTTIME = SUBSTR(HSMLOG,79,6);                                 

      ENDTIME   = SUBSTR(HSMLOG,91,6);                                 

      OUTPUT;                                                          

                    END;                                              

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Your data appears to be named input.  Therefore use named input read:

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

E.g.

data want;

     infile "xyz.txt";

     input tod= date= name=$ func=$ toval=$ frvol=$ devt=$;

run;

You should then have the variable to process the data as you like.

Astounding
PROC Star

Here's a way to make all the information available:

DATA OUT01;                                                       

      INFILE   HSMLOG;                                                   

   INPUT    @001    prior_HSMLOG       $120.  /

                 @001    HSMLOG               $120.;

   INDX1A = INDEX(HSMLOG,'FUNC=RECYCLE');                             

IF INDX1A GT 0 THEN DO;                  

...

END;

It assumes you are always working with 2 lines of raw data at a time.  If that's not the case, it gets a little more involved, but can still be done.  But let's only cross that bridge if necessary.  Good luck.

Good luck.

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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