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, 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 <>
Subject   Re: st: Problem parsing strings that contain "$CHAR"
Date   Wed, 21 Apr 2010 10:41:10 -0400 (EDT)


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.") {

Dan Blanchette
Research Associate
Center for Entrepreneurship and Innovation
Duke University's Fuqua School of Business

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

*   For searches and help try:

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