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

st: RE: RE: date function error?

From   "Hoffman, George" <>
To   <>
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 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,.)
	capture log using `logfile'
	if _rc==602 {
				while _rc==602 {capture log using
	if _rc!=0 	{
				di in red "could not open logfile"
				error _rc
	di "----log file:`logfile'----"

-----Original Message-----
[] On Behalf Of Nick Cox
Sent: Thursday, June 12, 2008 11:50
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

. di "$S_DATE" 

does that. 


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

*   For searches and help try:

*   For searches and help try:

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