Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: RE: passing macros to dictionary files
From
Joe Canner <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: RE: passing macros to dictionary files
Date
Wed, 23 Apr 2014 23:54:34 +0000
Doug,
Check out the -using()- option of the -infile- command. It allows you to specify the name of the input text file in the -infile- statement rather than in the dictionary file. If it is of interest to you, the help file gives details on what happens when the -using()- option for -infile- and the -using- qualifier in the dictionary file conflict.
Regards,
Joe Canner
Johns Hopkins University School of Medicine
________________________________________
From: [email protected] [[email protected]] on behalf of Douglas Levy [[email protected]]
Sent: Wednesday, April 23, 2014 4:34 PM
To: [email protected]
Subject: st: passing macros to dictionary files
Hi All,
I am trying to import a large number of files and aggregate them. My
strategy was to create <for> loops that generate macros with the
identifying file names (dates and cash register numbers). However, it
seems that I can't pass those macros on to the dictionary file, even
after converting the local macros from the <for> loops to global
macros that I thought I could pass to the dictionary file.
Here is an example of my code where I am trying to import data for the
first three days in March for registers 1 to 6:
forvalues x=1/3 {
local x=string(`x',"%02.0f")
forvalues myreg=1/6 {
local myreg=string(`myreg',"%02.0f")
global date_reg="201403`x'_`myreg'"
infile using "mydictionary.dct"
save "mynewfile.dta"
}
}
and the dictionary file is:
dictionary using "${date_reg}.csv" {str244 test}
When I run this, I get an error message suggesting that Stata did not
parse the macro at all:
file ${date_reg}.csv not found
dictionary invalid
Thoughts? Is it impossible to pass a macro to a dictionary file? If
so, is there another way to use a single dictionary for many different
files? Thanks in advance for your advice!
-Doug
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/