Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Keeping significant spaces with -infile- and -infix-


From   Alan Riley <[email protected]>
To   [email protected]
Subject   Re: st: Keeping significant spaces with -infile- and -infix-
Date   Fri, 18 May 2007 11:05:57 -0500

Joseph Coveney ([email protected]) wanted to know if it
was possible for leading and trailing spaces to be retained when
importing fixed-width ASCII files:

> How can significant unimbedded spaces of string variables be retained when
> importing fixed-width ASCII files?
> 
> -infile- with a dictionary truncates both the leading and trailing spaces of
> string variables.  An example of when this is inappropriate is illustrated
> below.  The example is a toy of a real data-management task in which
> long-string variables are read into Stata (in pieces that are 244 characters
> or less) from fixed-width ASCII files, manipulated as needed using Stata,
> and then exported to an ODBC-compliant application where they are
> reassembled by concatenation using SQL.
> 
> -infix- does the same truncation.

While Joseph and others have discussed some workarounds, there is
currently no elegant way to do this in Stata.  We will add one in
a future executable update.

-infile- with a dictionary accepts 's' as a format specifier to read a
set number of string characters.  Pieces of text brought in with 's'
have leading and trailing blanks stripped.  Joseph's example
dictionary used this:

> ----------------begin Mary.dct-----------------
> infile dictionary using Mary.dat {
>    _firstlineoffile(2)
>    str5 a_01 %5s
>    str5 a_02 %5s
>    str5 a_03 %5s
>    str5 a_04 %5s
>    str5 a_05 %5s
>    str5 a_06 %5s
>    str5 a_07 %5s "I'm all blank; -drop- me"
>    str2 line %2s "I'm a number; -destring- me"
> }
> ------------------end Mary.dct-----------------

We will introduce 'S' as an additional format specifier in a future
executable update.  After that, coding

    str5 a_01 %5S

in an -infile- dictionary would tell Stata to read 5 string characters,
preserving leading and trailing blanks.  Coding

    str5 a_01 %5s

would preserve the current behavior, telling Stata to read 5 string
characters, removing leading and trailing blanks.


Alan
([email protected])
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index