Page 2 of 2

Re: inserting new row for a column

PostPosted: Sat Mar 23, 2013 5:50 pm
by nikesh_rai
For summation, I used SAS.. I tried with SUM FIELDS.. but the problem with SUM FIELD is it will give a single row as a result and can not retain the added rows and values and even it can not retain the previously added value so that I can add the previous result with current row value. Here is the SAS is used for the same:

//STEPSAS  EXEC SAS                                             
//SAS.WORK DD UNIT=(SYSDA,59),SPACE=(CYL,(2500,2500)),         
//            DCB=(RECFM=FB,LRECL=904,BLKSIZE=0,DSORG=PS)       
//INFL01   DD DISP=SHR,DSN=&&TEMP12                                                     
//RESULT0  DD DSN=&&TEMP13,                                     
//            DISP=(,PASS,),                                   
//            UNIT=(FLXSHR,59),                                 
//            SPACE=(CYL,(100,100),RLSE),                       
//            DCB=(RECFM=FB,LRECL=140)                         
//SYSPRINT DD SYSOUT=*                                         
//SYSIN    DD *                                                 
DATA IN01 (KEEP=START_POS FIELD_NAME FIELD_LEN MOD_LEN SEQ_NUM);
INFILE INFL01  LENGTH=RECLEN;                                   
INPUT @05  START_POS        $10.                               
      @16  FIELD_NAME       $35.                               
      @60  FIELD_LEN        $10.                               
      @87  MOD_LEN          4.                                 
      @95  SEQ_NUM          4.       
 ;                                   
DATA _NULL_;                         
SET IN01;                             
RETAIN START_POS1 0;                 
START_POS1 = START_POS1 + MOD_LEN ;   
FILE RESULT0;                         
  PUT @05  START_POS        $10.     
      @16  FIELD_NAME       $35.     
      @60  FIELD_LEN        $10.     
      @87  MOD_LEN          4.       
      @95  START_POS1       4.       
 ;                                   

and the result was:

@1         WXXX-HXXX-DXX-PX-IX                         10.                 12      12
@7         WXXX-HXXX-PX-IX                             10.                 12      24
@13        WXXX-BXXX-EXXX-CXX-CX                       $1.                  3      27
@14        WXXX-PXXX-BXXX-IX                           $8.                 10      37
@22        WXXX-BXXX-EXXX-CX                           $8.                 10      47
@30        WXXX-BXX-SXX-DX                             $10.                12      59

Re: inserting new row for a column

PostPosted: Sat Mar 23, 2013 6:42 pm
by Robert Sample
So you are not aware of the LAG functions of SAS? Try this:
DATA IN01 (KEEP=START_POS FIELD_NAME FIELD_LEN MOD_LEN SEQ_NUM);
INFILE INFL01  LENGTH=RECLEN;                                   
INPUT @05  START_POS        $10.                               
      @16  FIELD_NAME       $35.                               
      @60  FIELD_LEN        $10.                               
      @87  MOD_LEN          4.                                 
      @95  SEQ_NUM          4.       
 ;                                   
DATA _NULL_;                         
SET IN01;                             
RETAIN START_POS1 0;                 
START_POS1 + MOD_LEN ;   
XSEQ = LAG1(START_POS1) ;
FILE RESULT0;                         
  PUT @05  START_POS        $10.     
      @16  FIELD_NAME       $35.     
      @60  FIELD_LEN        $10.     
      @87  MOD_LEN          4.       
      @95  XSEQ             4.       
 ;
I have not found much that SAS cannot do -- you need to learn to use the SAS web site to look at its documentation.

Re: inserting new row for a column

PostPosted: Sat Mar 23, 2013 6:48 pm
by nikesh_rai
Thanks Robert..

I have just started using SAS.. :) I will try this and will update in few minutes..

Re: inserting new row for a column

PostPosted: Sat Mar 23, 2013 7:01 pm
by nikesh_rai
I have no words.. what to say to you Robert and Billy.. except Thanks a lot.. :)
its working.. :)