Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: saving stata file using macro


From   "Jesper K. Hansen" <[email protected]>
To   [email protected]
Subject   Re: st: saving stata file using macro
Date   Thu, 10 Apr 2008 00:49:32 +0200

Nikh,

the problem is not -save- per se. The problem is the backslash (\) in
front of `1'. In Stata the backslash is used to prevent a macro (local
or global) from being expanded. Replace

-save $data_sc\`1',replace-

with

-save $data_sc/`1' , replace-

-- Jesper K. Hansen

On Wed, Apr 9, 2008 at 10:36 PM, nikh 2000 <[email protected]> wrote:
> In the following program I was trying to read a Access table using
>  ODBC command. It works fine except with saving command. I want to save
>  Stata file in the same name as Access file. When I used method-1 it
>  didn't work. Method-2 works fine. But I don't want to add any prefix
>  in the filename I saved. Any Idea how I could save without any
>  prefix?. I have to convert and save many Access tables into Stata
>  format.
>
>  Method-1:
>  cap prog drop readdata
>  prog def readdata
>         clear
>         odbc load, dsn("MS Access Database; DBQ=$acdata_sc") table("`1'") lower
>         count
>         save $data_sc\`1',replace
>  end
>
>  readdata        assetstatus
>
>  **
>  . readdata        assetstatus
>   3351
>  invalid '`'
>  r(198);
>
>
>  Method-2:
>  cap prog drop readdata
>  prog def readdata
>         clear
>         odbc load, dsn("MS Access Database; DBQ=$acdata_sc") table("`1'") lower
>         count
>         save x`1',replace
>  end
>
>  . readdata        assetstatus
>   3351
>  (note: file C:\xassetstatus.dta not found)
>  file C:\xassetstatus.dta saved
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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