LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 1996, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 17 Dec 1996 16:00:00 PST
Reply-To:     Melvin Klassen <KLASSEN@UVVM.UVIC.CA>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Melvin Klassen <KLASSEN@UVVM.UVIC.CA>
Subject:      Re: Writing out a Variable Block File

Amy Majeske <AMAJESK@CMS.CC.WAYNE.EDU> writes: >I'm reading in a VB file of max length 1252 and trying to write out a >VB file with the same file characteristics. I need to switch around >the order of some of the fields in the first 14 bytes.

Use: INFILE fileref LENGTH= LRECL;

to obtain the actual-size of each record.

Then, read the first 52 bytes, and "hold" the record.

INPUT @; ACTUAL = MIN(LENGTH(HEADER),LRECL); INPUT HEADER $VARYING52. ACTUAL @; LENHEAD = ACTUAL;

Now, read the remaining up-to-1200 bytes into 6 200-byte variables:

LENGTH SEG1-SEG6 $ 200; ARRAY SEGS SEG1-SEG6; ARRAY LENS LEN1-LEN6;

DO OVER LENS; LENS = 0; END; /* Initialize. */

ACTUAL = LRECL - ACTUAL;

SEGNUM = 0;

DO WHILE (ACTUAL > 0); SEGNUM = SEGNUM + 1;

LEN = MIN(200,ACTUAL); INPUT SEGS {SEGNUM} $VARYING200. LEN @ ; LENS {SEGNUM} = LEN;

ACTUAL = ACTUAL - LEN;

END;

Now, you know the actual-size of the record, and the actual-size of each of the 6 "segments", with "zero" values for the ones which weren't needed for each record.

>Like most VB files, some records have 200 bytes, some have 800, and >some have the full 1252 bytes. >My first three lines look like this: > DATA STUDATA; > INFILE STUDATA TRUNCOVER; > INPUT VAR1 1-2 VAR2 2-5 .... VAR100 1251-1252;

It's odd that VAR1 and VAR2 *both* process column '2'.

>The problem comes on my FILE and PUT statements. (There's no comparable >TRUNCOVER option for the FILE statement.) SAS can't seem to write it >out the same way.

SAS can do the following:

PUT HEADER $VARYING52. LENHEAD @;

DO SEG=1 TO 6; TEMP = LENS {SEG}; IF TEMP > 0 THEN PUT SEGS {SEG} $VARYING200. TEMP @; END;


Back to: Top of message | Previous page | Main SAS-L page