I am developing this wrapper around tempfile
in Stata to handle multiple datasets at the same time without having to save them in current directory. So in essence I want Stata to mimic SAS, and that is the reason the program name is work; the initial code is without any options and minimal functionality. I have adhere to your advice not to tokenize and program works; however the issue is once I recall the tempfile in further program, this program (work) do not pass the handle to the next to call the tempfile.
code for "work"
capture program drop work
program define work
version 12.1
syntax [name(id="file name")] [, sort(string) ]
*tokenize namelist
*di "namelist'"
*if "nol'" !="" | "nol'" !="" | "nolabel'" !="" {
* di "``namelist''"
*}
tempfile namelist'
*di "namelist'"
if "sort'" != "" {
sortsort'
}
di "File 'namelist'' saved in following temporary work folder"
save ` namelist''
*di "Now you can use temporary file =namelist'' in your program"
end
Once I call the temporary file within my do file as follows this error emerge:
work Orig File 'Orig' saved in following temporary work folder file C:\Users\saa602\AppData\Local\Temp\ST_00000001.tmp saved
. di "`Orig'"
. use `Orig', replace
invalid file specification
Please note that I have been using tempfile
successfully to handle multiple files, especially once merging large number of files without any hassle; however a wrapper program with options to sort and show the work directory location would be very handy for all of us.