Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Problem parsing strings that contain "$CHAR"


From   <benoit.hebert@hrsdc-rhdcc.gc.ca>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Problem parsing strings that contain "$CHAR"
Date   Thu, 22 Apr 2010 12:11:12 -0400

Thanks to Vince Wiggins and Nick Cox. An e-mail exchange with Dan Blanchette made me realize that I was wrong, when testing my Stata code, in assuming that I would get the same results whether the problematic string was defined as a local or actually read from a file. 

When the string is defined as a local:

   . loc line @04080    Variable_C    $CHAR6.

I get:

   . di `"`macval(line)'"'
   @04080    Variable_C    .

But when it is read from a text file, e.g.:

   . type c:\data\test.sas
   @04060    Variable_A    5.
   @04065    Variable_B    10.4
   @04075    Variable_C    $5.
   @04080    Variable_D    $CHAR6.
   @04086    Variable_E    $CHAR4.;

Then there is no macro substitution:

   . tempname sasfile

   . file open `sasfile' using c:\data\test.sas, read text

   . file read `sasfile' line

   . while r(eof) != 1 {
     2.     di as res `"`macval(line)'"'
     3.    file read `sasfile' line
     4. }
   @04060    Variable_A    5.
   @04065    Variable_B    10.4
   @04075    Variable_C    $5.
   @04080    Variable_D    $CHAR6.
   @04086    Variable_E    $CHAR4.;

   .

Which means that with appropriate search-and-replace and parsing commands, I can extract the relevant info from the strings. I understand that my life would be easier if I knew Mata, but that will be for another day...

Benoit-Paul Hebert
Recherche en politiques / Policy Research
RHDCC/HRSDC



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index