automating adding a date to a chart

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

automating adding a date to a chart

Paul Mcgeoghan
Hi,

I have data where I produce charts on a certain date:

I have data as follows:
Measure Time DatePeriod
20 7:05       21-Mar-2009
30 7:10
40 7:15
60 7:20
etc

I can autofill the DatePeriod down if required using syntax. By default the
DatePeriod appears in the first row though and is always a single date (as
the data are data logs obtained on a single day).

So I produce a line chart via
Graphs Legacy Dialogs Line Simple and values of individual cases
Lines represent Measure
Variable is Time

So this produces a line chart with the times on horizontal.

I need some way of automating putting the Date on the chart as a Title or
Footnote or some method.

Alternativaly, would there be a way of automating saving the Output file
extracting the Date from the data so I would have Charts_21_Mar_2009.spv

As a last resort, I can just produce a Frequency Table in the Output file
which will show me the Date in the Output file.

If anyone has any ideas?
Thanks,
Paul

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: automating adding a date to a chart

Richard Ristow
At 10:30 AM 4/22/2009, Paul McGeoghan wrote:

I have data where I produce charts on a certain date:

I have data as follows:
Measure Time DatePeriod
20 7:05       21-Mar-2009
30 7:10
40 7:15
60 7:20
etc

I need some way of automating putting the Date on the chart as a Title or Footnote or some method.

Can you use the SPSS system variables that give you the current date and time? From the Command Syntax Reference:

System variables are special variables created during a working session to keep system-required
information, such as the number of cases read by the system, the system-missing value, and the
current date. System variables can be used in data transformations.
.. The names of system variables begin with a dollar sign ($).
.. You cannot modify a system variable or alter its print or write format. Except for these
restrictions, you can use system variables anywhere that a normal variable is used in the
transformation language.
.. System variables are not available for procedures.
[...]
$JDATE
Current date in number of days from October 14, 1582 (day 1 of the Gregorian calendar). The format is F6.0 .
$DATE Current date in international date format with two-digit year. The format is A9 in the form dd-mmm-yy.
$DATE11 Current date in international date format with four-digit year. The format is A11 in the form dd-mmm-yyyy.
$TIME Current date and time. $TIME represents the [current date and time as an SPSS date-time value, namely] the number of seconds from midnight, October 14, 1582, to the date and time when the transformation command is executed. The format is F20 .

Alternativaly, would there be a way of automating saving the Output file extracting the Date from the data so I would have Charts_21_Mar_2009.spv

That's meta-code -- writing SPSS code based on file data. The currently favored way is to use Python. An older method was to use transformation commands to write the code to an external file, then INCLUDE/INSERT the code.
===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: automating adding a date to a chart

Peck, Jon

 

 


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Richard Ristow
Sent: Thursday, April 23, 2009 9:15 AM
To: [hidden email]
Subject: Re: [SPSSX-L] automating adding a date to a chart

 

At 10:30 AM 4/22/2009, Paul McGeoghan wrote:


I have data where I produce charts on a certain date:

I have data as follows:
Measure Time DatePeriod
20 7:05       21-Mar-2009
30 7:10
40 7:15
60 7:20
etc

I need some way of automating putting the Date on the chart as a Title or Footnote or some method.

[>>>Peck, Jon] One way to do this is with a small amount of Python code.

 

In the code below, the chart specification was generated from the ChartBuilder.  The title contains the string "%(curdate)s".  Wrapping this in a Python program would produce something like this.

 

begin program.

import time

curdate = time.asctime()

cmd = """GGRAPH

  /GRAPHDATASET NAME="graphdataset" VARIABLES=jobcat COUNT()[name="COUNT"] MISSING=LISTWISE

    REPORTMISSING=NO

  /GRAPHSPEC SOURCE=INLINE.

BEGIN GPL

  SOURCE: s=userSource(id("graphdataset"))

  DATA: jobcat=col(source(s), name("jobcat"), unit.category())

  DATA: COUNT=col(source(s), name("COUNT"))

  GUIDE: axis(dim(1), label("Employment Category"))

  GUIDE: axis(dim(2), label("Count"))

  GUIDE: text.title(label("the chart title %(curdate)s"))

  SCALE: cat(dim(1), include("1", "2", "3"))

  SCALE: linear(dim(2), include(0))

  ELEMENT: interval(position(jobcat*COUNT), shape.interior(shape.square))

END GPL.""" % locals()

spss.Submit(cmd)

end program.

 

This puts something like "Fri Ar 24 13:03:30 2009" in the title in the indicated location.  Many other date/time formats are possible.

 

 

 


Can you use the SPSS system variables that give you the current date and time? From the Command Syntax Reference:

System variables are special variables created during a working session to keep system-required
information, such as the number of cases read by the system, the system-missing value, and the
current date. System variables can be used in data transformations.
.. The names of system variables begin with a dollar sign ($).
.. You cannot modify a system variable or alter its print or write format. Except for these
restrictions, you can use system variables anywhere that a normal variable is used in the
transformation language.
.. System variables are not available for procedures.
[...]
$JDATE
Current date in number of days from October 14, 1582 (day 1 of the Gregorian calendar). The format is
F6.0 .
$DATE Current date in international date format with two-digit year. The format is
A9 in the form dd-mmm-yy.
$DATE11 Current date in international date format with four-digit year. The format is
A11 in the form dd-mmm-yyyy.
$TIME Current date and time. $TIME represents the [current date and time as an SPSS date-time value, namely] the number of seconds from midnight, October 14, 1582, to the date and time when the transformation command is executed. The format is
F20 .


Alternativaly, would there be a way of automating saving the Output file extracting the Date from the data so I would have Charts_21_Mar_2009.spv

[>>>Peck, Jon] There is a function in the spssaux2.py Python module that will build file names containing the current date.  The function is

CreateFileNameWDate.  You could use it like this:

begin program.

import spss, spssaux2

fn = spssaux2.CreateFileNameWDate("Charts.spv")

spss.Submit("OUTPUT SAVE OUTFILE="%(fn)s" % locals())

end program.

 

This would save the Viewer contents as a file with a name like "Charts 2009-04-24-01:12.spv".

The spssaux2 module would be needed from Developer Central.  Of course both of these solutions require the Python plugin.

 

HTH,

Jon Peck


That's meta-code -- writing SPSS code based on file data. The currently favored way is to use Python. An older method was to use transformation commands to write the code to an external file, then INCLUDE/INSERT the code.


===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD