View previous topic :: View next topic
|
Author |
Message |
mushreyas
New User
Joined: 18 Jul 2008 Posts: 59 Location: Bangalore
|
|
|
|
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 |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
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 |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
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 |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Expat - clever piece of code, I learnt something.
Thank you |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
Hi Bill - thanks for the correction. Duly noted. |
|
Back to top |
|
|
mushreyas
New User
Joined: 18 Jul 2008 Posts: 59 Location: Bangalore
|
|
|
|
Thanks expat. |
|
Back to top |
|
|
|