IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Handling Variable length files in SAS/WPS code


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
mushreyas

New User


Joined: 18 Jul 2008
Posts: 59
Location: Bangalore

PostPosted: Fri Oct 31, 2014 11:12 am
Reply with quote

Hi,

I have requirement wherein i have to handle variable length file in a SAS code to generate a CSV file. File layout is given below.

Code:
01 IRB-DATA
     02 IRB-LEN              PIC 9(4).
     02 IRB-ACCOUNT     PIC X(5).
     02 IRB-GROUP         PIC X(5).
     02 IRB-NAME-CNT    PIC 9.
     02 IRB-NAME-GRP    OCCURS 1 TO 9 TIMES
                                   DEPENDING ON IRB-NAME-CNT.
         05 IRB-TITLE       PIC X(10).
         05 IRB-FORNM     PIC X(15).
         05 IRB-SURNAME PIC X(15).
     02 IRB-MEM-FLG    PIC X(1).

Am facing issue while trying to determine the exact position of IRB-MEM-FLG as am not sure how to handle this using SAS. Any help would be appreciated?
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1689
Location: Tiruppur, India

PostPosted: Fri Oct 31, 2014 2:28 pm
Reply with quote

Hello,
Could you post few sample records having different IRB-NAME-CNT values.

So we could be able to possibly frame a INPUT statement from it.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8794
Location: Welsh Wales

PostPosted: Fri Oct 31, 2014 2:51 pm
Reply with quote

Not really sure what the problem is here, it is just elementary mathematics.

The length of the occurs group field is 40 bytes and starts in column 16, so you multiply the number of occur group fields by 40, add 16 et voila.

Perform a do loop for the count variable and then you can easily treat either the whole grouped field as an array or its components as three seperate arrays.

So, as I was a bit bored today .........................
Code:
Data OUT_01 (DROP = POS aa) ;
  ARRAY   IRB_NAME_GRPA      $40.  GRPA01 - GRPA09;
  infile  datalines;
      input   @01 IRB_LEN          4.
              @05 IRB_ACCOUNT     $5.
              @10 IRB_GROUP       $5.
              @15 IRB_NAME_CNT     1.          @;

  POS = 16;

  DO aa = 1 to IRB_NAME_CNT;
     input @POS IRB_NAME_GRPA{aa}     $40. @;
     POS + 40;   
  END;

  INPUT @POS IRB_MEM_FLG     $1.;

DATALINES;
1000ABCDEabcde11234567890ABCDEFGHIJKLMNOabcdefghijklmnoZ
2000abcdeABCDE20987654321abcdefghijklmnoABCDEFGHIJKLMNO0987654321abcdefghijklmnoABCDEFGHIJKLMNOY
;
run;

proc print noobs; run;
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1015
Location: Richmond, Virginia

PostPosted: Fri Oct 31, 2014 6:05 pm
Reply with quote

Note that your title is wrong - the record length is not variable.

All of the IRB-NAME-GRP elements may not be populated, but they do occupy positions.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1689
Location: Tiruppur, India

PostPosted: Sat Nov 01, 2014 3:32 am
Reply with quote

Expat - clever piece of code, I learnt something.
Thank you
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7311
Location: Inside the Matrix

PostPosted: Sat Nov 01, 2014 5:17 am
Reply with quote

Phry... Phil, not quite.

The stupid thing in the definition is to have put anything after the OCCURS DEPENDING ON.

If IRB-NAME-CNT is zero, it is immediately followed by IRB-MEM-FLG (IRB-NAME-GRP will have zero length).

If IRB-NAME-CNT is three, IRB-MEM-FLG will be 120 bytes after it (IRB-NAME-GRP will have a length of 120).

If that structure is written to a file, the records will be variable-length.

In the WORKING-STORAGE (or LOCAL-STORAGE) SECTION, storage will be set aside for a fixed length, but the length of the group and therefore the position of anything after that, depend on the value of IRB-NAME-CNT.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1015
Location: Richmond, Virginia

PostPosted: Sat Nov 01, 2014 6:02 am
Reply with quote

Hi Bill - thanks for the correction. Duly noted.
Back to top
View user's profile Send private message
mushreyas

New User


Joined: 18 Jul 2008
Posts: 59
Location: Bangalore

PostPosted: Sat Nov 01, 2014 9:48 pm
Reply with quote

Thanks expat.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts Execute step regardless of previous s... JCL & VSAM 2
No new posts Error 0C1 Reason Code 1 with branch i... PL/I & Assembler 3
This topic is locked: you cannot edit posts or make replies. Copy list of files from PS to another... CLIST & REXX 11
No new posts FILE STATUS - 39 ON VARIABLE LENGTH V... COBOL Programming 2
No new posts JOINKEYS to match two input files on ... DFSORT/ICETOOL 3
Search our Forums:

Back to Top