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 on April 23, 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   Dan Blanchette <dan.blanchette@duke.edu>
To   benoit.hebert@hrsdc-rhdcc.gc.ca, statalist@hsphsun2.harvard.edu
Subject   Re: st: Problem parsing strings that contain "$CHAR"
Date   Wed, 21 Apr 2010 10:41:10 -0400 (EDT)

Hello,

Am thinking you're reading in a SAS program into stata using
-file open- and -file read-, right?

If so, you should use macval() to keep Stata from evaluating
what Stata thinks to be a global macro: $CHAR6

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

You can also use it inside functions, but you then have to implement Nick Cox's suggestion of escaping the dollar sign:

if strpos("`macval(line)'","\$CHAR6.") {
 ...
}

HTH,
Dan Blanchette
Research Associate
Center for Entrepreneurship and Innovation
Duke University's Fuqua School of Business
dan.blanchette@duke.edu

Dear Stata users,

I have to parse the lines of SAS syntax files that contain 1) the position of a variable in a raw data file, 2) the
name of the variable, and 3) the data type of the variable. Examples of such lines are:

@04075    Variable_B    $5.
@04080    Variable_C    $CHAR6.

Both "$#" and "$CHAR#" mean that the variable is a string variable of # characters. I have no problem parsing the
first line above, but am looking for advice on what to do with lines that contain a sequence like "$CHAR6". Such
sequences appear to be evaluated first and before the string is parsed, and results in "", as in below:

. loc line @04080    Variable_C    $CHAR6.
. di "`line'"
@04080    Variable_C    .

Commands like regexm and tokenize or functions like subinstr also see "." instead of "$CHAR6.", making it impossible
(for me at least) to retrieve all the relevant information in these lines.

Any help appreciated,

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