Date: Tue, 13 Jun 2000 17:17:39 +0100
Reply-To: peter.crawford@DB.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Peter Crawford <peter.crawford@DB.COM>
Subject: Re: Variable length
Content-type: text/plain; charset=us-ascii
As the data is delimited (surely), say with delimiter &delim, here is some "brute force" code to magically calculate the lengths of all columns
%let delim=|; /* a pipe mark in my testing***/
data lengths(keep = col len ) ;
array cols(32000) _temporary_; /** allow too many columns */
infile "<your raw data file>" dsd dlm="&delim"
lrecl=50000 /*should be wide enough **/
eof=eod /* action at end of data **/
firstobs=2 /* skipping column headers */
truncover /* should be ok, but ...**/
column=posn /*the infile statement indicates its current position*/
;
length str $200; /* something to read */
do col= 1 by 1 while( po ^= posn ); /* until at end of input */
po = posn ; /* store "previous position" **/
input str @ ;
len = posn - po ; /* column length in raw data **/
cols(col) = max( cols(col), len );
end;
return;
eod:
do col = 1 by 1 while( cols( col ) ne . );
len = cols( col );
output ; /* or call execute into macro variables*/
end;
run;
Datum: 13.06.2000 16:04
An: SAS-L@listserv.uga.edu
Antwort an: Richard.Simhon@cornhill.co.uk
Betreff: Variable length
Nachrichtentext:
Hi all,
Can anyone tell me if there is a way of finding out how long the variables
in a text file are, prior to importing the file into a SAS data set. This is
not much of a problem for those fields that are <=8 characters wide. I'm
using Windows NT and SAS 6.12
Thanks in advance.
Richard
Email Richard.Simhon@Cornhill.co.uk
**********************************************************************
Copyright in this message and any attachments remains with us. It is
confidential and may be legally privileged. If this message is not
intended for you it must not be read, copied or used by you or
disclosed to anyone else. Please advise the sender immediately if
you have received this message in error.
Although this message and any attachments are believed to be free of
any virus or other defect that might affect any computer system into
which it is received and opened it is the responsibility of the
recipient to ensure that it is virus free and no responsibility
is accepted by Cornhill Insurance PLC for any loss or damage in any
way arising from its use.
Cornhill Insurance Plc, Registered in England number 84638,
Registered Office 32 Cornhill, London EC3V 3LJ.
**********************************************************************