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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1248 views
  • 0 likes
  • 3 in conversation