Statalist


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

st: RE: RE: date function error?


From   "Hoffman, George" <ghoffman@mcw.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: date function error?
Date   Thu, 12 Jun 2008 13:37:47 -0500

Thank you, Nick.
well, then the problem is somewhere else. my real question is about a
automatic log-creation program that i have run from a profile.do file at
stata startup, which has been malfunctioning.

my intent was to creat a log file with the name mmddhhmm.log, where mmdd
comes from $S_DATE and hhmm comes from $S_TIME.  my program has looked
like this for years, and it has no longer been able to add the mmdd part
because my call to date("$S_DATE","dmy" returns  missing value:
the program is below.
 thanks for helping me out of this rut.

george hoffman


program define autolog
	local logdir=".\logs\"
	local logfile : display  %dND date("$S_DATE","dmy")
substr("$S_TIME",1,2) substr("$S_TIME",4,2)
	local logfile : display "`logdir'" substr("`logfile'",5,.)
".log"
	capture log using `logfile'
	if _rc==602 {
				while _rc==602 {capture log using
`logfile'}
				}
	if _rc!=0 	{
				di in red "could not open logfile"
				error _rc
				}
	di "----log file:`logfile'----"
end
	
	
	
	

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Thursday, June 12, 2008 11:50
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: date function error?

No Stata error here, just a subtle misunderstanding. 

Step 1. Stata substitutes macro names by their contents. 

Step 2. -display- sees 12Jun and tries to make sense of it but fails.
12Jun is not a number, nor a variable name, nor a scalar name. 

Solution: You need to spell out to Stata that you are dealing with a
string. 

. di "$S_DATE" 

does that. 

Nick
n.j.cox@durham.ac.uk 

Hoffman, George


i've got stata 10 on win32, and have been troubled by an error in the
date function:

. di $S_DATE
12Jun not found
r(111);


*
*   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/

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index