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   "Austin Nichols" <>
Subject   Re: st: Keeping significant spaces with -infile- and -infix-
Date   Fri, 18 May 2007 11:50:08 -0400

A minor generalization of your workaround uses -hexdump- to identify a
character otherwise unused in the input file as the "target" for all
spaces first (not tested thoroughly, just illustrative):

qui hexdump Mary.dat, res
local n=1
local i=160
while `n'>0 {
local n=r(c`i')
if `n'==0 local target="\"+"`i'"
local i=`i'+1
di `i'
if `i'==256 {
di as err "All char 160-255 in file"
error 198
tempfile tmpfil0
filefilter Mary.dat "`tmpfil0'", from(" ") to(`target'd)
quietly infile using Mary.dct, using("`tmpfil0'") clear
foreach var of varlist _all {
  capture assert indexnot(`var', char(160)) == 0
  if !_rc {
      drop `var'
  quietly replace `var' = subinstr(`var', char(160), " ", .)
  quietly destring `var', replace
generate str A = a_01 + a_02 + a_03 + a_04 + a_05 + a_06
list A, noobs separator(0)
*   For searches and help try:

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