Date: Thu, 15 Apr 2004 11:48:17 -0600
Reply-To: Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
Subject: Re: PUTting a fixed width text file
Content-Type: text/plain; charset=us-ascii
Leading blanks are preserved in a put statement:
=====
337 data _null_;
338 a = ' a';
339 put @1 '12345678'
340 / @1 a $8.
341 ;
342 run;
12345678
a
NOTE: DATA statement used:
real time 0.00 seconds
cpu time 0.00 seconds
=====
Perhaps the problem is that leading blanks are being stripped when the
data are read in. If so, use the $CHAR informat:
=====
374 data _null_;
375 input @1 a $8.
376 @1 b $char8.
377 ;
378 put _infile_
379 / @1 a $char8.
380 / @1 b $char8.
381 ;
382 cards;
78
78
78
NOTE: DATA statement used:
real time 0.01 seconds
cpu time 0.00 seconds
=====
The safest course is to use $CHAR on both input and output.
--
JackHamilton@FirstHealth.com
Manager, Technical Development
Metrics Department, First Health
West Sacramento, California USA
>>> "Frustino, Stephen" <SFrustino@COLLEGEBOARD.ORG> 04/15/2004 10:34
AM >>>
Dear colleagues,
I've been working with a number of procedures to read data from fixed
width
text files in one format and writing back subsets of it into multiple
fixed
width text files in a different format. A recurring issue has been
when a
variable being read in has leading blanks, it appears as left justified
in
the output file. However, those leading blanks are significant.
Sometimes
the variables also have trailing blanks. So what I end up doing is
reading
in a dummy variable that starts at the same point as the real variable
that
I want to write and ends at a point in the file at which I know that
there
will be a non-blank. I then use that variable in a piece of code as
follows:
@ 903 + (min(47, (63-length(LEFT(VarDummy))))) VarReal
It works, but it's cumbersome. Would anyone have a better way of
preserving
leading blanks when using the PUT statement? Any suggestions would be
appreciated. Thanks!
Stephen