Using Graph Templates

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

Using Graph Templates

BBH123
Hi,

I'm including a graph in my macro on spss, and from the information I have found in this discussion and from my own experience, you cannot just use the usual graph syntax in a macro as it keeps running 'INLINE' forever!

I think that using a graph template should get around that - my predecessor seemed to be using that with no problem anyway, but unfortunately I just can't get my template to work - I think my syntax is incorrect. My syntax for my original graph is:

* Chart Builder.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=ses_ayrc COUNT()[name="COUNT"] Modeofattendance MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: ses_ayrc=col(source(s), name("ses_ayrc"), unit.category())
  DATA: COUNT=col(source(s), name("COUNT"))
  DATA: Modeofattendance=col(source(s), name("Modeofattendance"), unit.category())
  GUIDE: axis(dim(1), label("Academic Year"))
  GUIDE: axis(dim(2), label("Number of Students"))
  GUIDE: legend(aesthetic(aesthetic.shape.interior), label("Mode of Attendance"))
  GUIDE: text.title(label("Student Numbers"))
  SCALE: linear(dim(2), include(0))
  ELEMENT: line(position(ses_ayrc*COUNT), shape.interior(Modeofattendance), missing.wings())
END GPL.

And then I saved the outputted chart as a .sgt template. When I tried to then use this template I used the following syntax:

GRAPH
 /LINE(MULTIPLE) COUNT(ses_ayrc) BY ses_ayrc BY Modeofattendance
/TEMPLATE='...filepathway...\Student Numbers.sgt'

Which I'm sure is totally wrong as I get three error messages:

>Error # 701 in column 18.  Text: COUNT
>An undefined variable name, or a scratch or system variable was specified in a
>variable list which accepts only standard variables.  Check spelling and
>verify the existence of this variable.
>Execution of this command stops.
 
>Warning # 17849
>The requested line chart type cannot be drawn with the provided data.
>Instead, Graphics will attempt to draw a simple line chart.
 
>Error # 17819 in column 23.  Text: (
>Expected "/" was not found.  Perhaps either the "/" between subcommands was
>omitted, or if a chart type was specified, the variable specifications are
>invalid for the requested chart.  Skipping to a "/".

I'm sure the first line is wrong, but I can't work out how to word it as it seems totally different when using templates?

Any help would be greatly appreciated!

Many thanks
Reply | Threaded
Open this post in threaded view
|

Re: Using Graph Templates

ViAnn Beadle
GPL requires quotation marks and macros strip them out. So you have to use
the CONCAT operator to force them back in for EVERY string in apostrophes
within the BEGIN GPL-END GPL block. Add these token to your macro
definition. Here's an example.

DEFINE freqchart
        (varname= !TOKENS(1)
        /label= !TOKENS(1))
        !LET !qvarname=!CONCAT('"',!varname,'"')
        !LET !qlabel=!CONCAT('"',!UNQUOTE(!label),'"')
        !LET !gdataset=!CONCAT('"',graphdataset,'"')
        !LET !ylabel=!CONCAT('"',Count,'"')
GGRAPH
  /GRAPHDATASET NAME='graphdataset' VARIABLES=!varname COUNT()[name='COUNT']
MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id(!gdataset))
  DATA: x=col(source(s), name(!qvarname), unit.category())
  DATA: COUNT=col(source(s), name(!UPCASE(!ylabel)))
  GUIDE: axis(dim(1), label(!qlabel))
  GUIDE: axis(dim(2), label(!ylabel))
  SCALE: linear(dim(2), include(0))
  ELEMENT: interval(position(x*COUNT), shape.interior(shape.square))
END GPL.
!ENDDEFINE.


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
BBH123
Sent: Thursday, March 17, 2011 9:41 AM
To: [hidden email]
Subject: Using Graph Templates

Hi,

I'm including a graph in my macro on spss, and from the information I have
found in this discussion and from my own experience, you cannot just use the
usual graph syntax in a macro as it keeps running 'INLINE' forever!

I think that using a graph template should get around that - my predecessor
seemed to be using that with no problem anyway, but unfortunately I just
can't get my template to work - I think my syntax is incorrect. My syntax
for my original graph is:

* Chart Builder.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=ses_ayrc COUNT()[name="COUNT"]
Modeofattendance MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: ses_ayrc=col(source(s), name("ses_ayrc"), unit.category())
  DATA: COUNT=col(source(s), name("COUNT"))
  DATA: Modeofattendance=col(source(s), name("Modeofattendance"),
unit.category())
  GUIDE: axis(dim(1), label("Academic Year"))
  GUIDE: axis(dim(2), label("Number of Students"))
  GUIDE: legend(aesthetic(aesthetic.shape.interior), label("Mode of
Attendance"))
  GUIDE: text.title(label("Student Numbers"))
  SCALE: linear(dim(2), include(0))
  ELEMENT: line(position(ses_ayrc*COUNT), shape.interior(Modeofattendance),
missing.wings())
END GPL.

And then I saved the outputted chart as a .sgt template. When I tried to
then use this template I used the following syntax:

GRAPH
 /LINE(MULTIPLE) COUNT(ses_ayrc) BY ses_ayrc BY Modeofattendance
/TEMPLATE='...filepathway...\Student Numbers.sgt'

Which I'm sure is totally wrong as I get three error messages:

>Error # 701 in column 18.  Text: COUNT
>An undefined variable name, or a scratch or system variable was
>specified
in a
>variable list which accepts only standard variables.  Check spelling
>and verify the existence of this variable.
>Execution of this command stops.

>Warning # 17849
>The requested line chart type cannot be drawn with the provided data.
>Instead, Graphics will attempt to draw a simple line chart.

>Error # 17819 in column 23.  Text: (
>Expected "/" was not found.  Perhaps either the "/" between subcommands
>was omitted, or if a chart type was specified, the variable
>specifications are invalid for the requested chart.  Skipping to a "/".

I'm sure the first line is wrong, but I can't work out how to word it as it
seems totally different when using templates?

Any help would be greatly appreciated!

Many thanks

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Using-Graph-Templates-tp388488
4p3884884.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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

=====================
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
|

Negative values in macro

ANDRES ALBERTO BURGA LEON
In reply to this post by BBH123

Hello to all.

I'm tryign to run this macro but I get an error:


**************************************************************************************************************************************.
DEFINE Medidas (base = !TOKENS(1) / area = !TOKENS(1) / corteN1 = !TOKENS(1) / corteN2 = !TOKENS(1)  / literal = !TOKENS(2)).

GET FILE=!QUOTE(!CONCAT ('D:\Censo Alumnos 2010\Definitiva\Cuarto\Rasch\',!base,'\',!base,'_',!area,'_P.sav')).
DATASET NAME !CONCAT(!base,!area) WINDOW=FRONT.

RENAME VARIABLES (measure = !CONCAT('medida_',!area)) (s.e# = !CONCAT('error_',!area)) (inmnsq = !CONCAT('infit_',!area)) (outmnsq = !CONCAT('outfit_',!area)).

STRING cod_mod7 (A7).
COMPUTE cod_mod7 = SUBSTR(NAME,1,7) .
EXECUTE .

STRING anexo (A1).
COMPUTE anexo = SUBSTR(NAME,8,1) .
EXECUTE .

STRING seccion (A1).
COMPUTE seccion = SUBSTR(NAME,9,1) .
EXECUTE .

STRING cod_al (A2).
COMPUTE cod_al = SUBSTR(NAME,10,2) .
EXECUTE .

SORT CASES BY cod_mod7 (A) anexo (A) seccion (A) cod_al(A).

DELETE VARIABLES entry status ptmeasur pvalue name.

IF ( !CONCAT('medida_',!area) <  !corteN1) !CONCAT('grupo_3',!area) = 1 .
IF ( !CONCAT('medida_',!area) >=  !corteN1 AND !CONCAT('medida_',!area) < !corteN2) !CONCAT('grupo_3',!area) = 2 .
IF (!CONCAT('medida_',!area) >= !corteN2) !CONCAT('grupo_3',!area) = 3 .
EXECUTE.

FORMATS !CONCAT('grupo_3',!area) (F1.0) !CONCAT('medida_',!area) (F4.3) !CONCAT('error_',!area) (F4.3) !CONCAT('infit_',!area) (F3.2) !CONCAT('outfit_',!area) (F3.2).

VARIABLE LEVEL !CONCAT('grupo_3',!area) (ORDINAL).

VALUE LABELS !CONCAT('grupo_3',!area)
1 '< Nivel 1'
2 'Nivel 1'
3 'Nivel 2'.

VARIABLE LABELS
!CONCAT('medida_',!area) !QUOTE(!CONCAT('Medida ',!base))
!CONCAT('error_',!area) !QUOTE(!CONCAT('Error ',!base))
!CONCAT('infit_',!area) !QUOTE(!CONCAT('Infit ',!base))
!CONCAT('outfit_',!area) !QUOTE(!CONCAT('Outfit ',!base))
!CONCAT('grupo_3',!area) !QUOTE(!CONCAT('Nivel de desempeño en ',!base))

************************************************************************************************************************************.

*CONVERTIR CADA NIVEL EN UNA VARIABLE.

IF (!CONCAT('grupo_3',!area)=1) !CONCAT('g1_',!area) = 1 .
IF (!CONCAT('grupo_3',!area)=2)  !CONCAT('g2_',!area) = 1 .
IF (!CONCAT('grupo_3',!area)=3)  !CONCAT('g3_',!area) = 1 .
EXECUTE .

FORMATS !CONCAT('g1_',!area) !CONCAT('g2_',!area) !CONCAT('g3_',!area) (F1.0).

VARIABLE LABELS !CONCAT('g1_',!area) !QUOTE(!CONCAT('Grupo 1 ', !base)).
VARIABLE LABELS !CONCAT('g2_',!area) !QUOTE(!CONCAT('Grupo 2 ', !base)).
VARIABLE LABELS !CONCAT('g3_',!area) !QUOTE(!CONCAT('Grupo 3 ', !base)).

RECODE !CONCAT('g1_',!area) !CONCAT('g2_',!area) !CONCAT('g3_',!area) (SYSMIS=0).
EXECUTE.

SAVE OUTFILE =!QUOTE(!CONCAT ('D:\Censo Alumnos 2010\Definitiva\Cuarto\Rasch\',!base,'\',!base,'_',!area,'_P.sav'))
/COMPRESSED.

DATASET CLOSE !CONCAT(!base,!area).

!ENDDEFINE.


Medidas base=Aimara area= L1 corteN1=0.319 corteN2=1.483 .
Medidas base=Awajun area= L1 corteN1=0.202 corteN2= 1.796.
Medidas base=Quechua area= L1 corteN1= -0.244 corteN2= 1.784.
Medidas base=Shipibo area= L1 corteN1=0.568 corteN2= 1.175.

All works fine, but I have a trouble with the N1 = -0.244

I get this warning. I'm not sure what could be wrong
Warnings
Expecting word or = sign. Found 0.244.
Execution of this command stops.



Kindly
Andrés

Mg. Andrés Burga León
Coordinador de Análisis e Informática
Unidad de Medición de la Calidad Educativa
Ministerio de Educación del Perú
Calle El Comercio s/n (espalda del Museo de la Nación)
Lima 41
Perú
Teléfono 615-5840
Reply | Threaded
Open this post in threaded view
|

Re: Negative values in macro

David Marso
Administrator
Greetings Andres,
Without getting into the idiosyncrasies of the MACRO parser or attempting to explicate WTH constitutes a "TOKEN"  I provide the following 2 working macros for you to ponder.  I leave it to you to adapt yours appropriately.
HTH, David

---
define test1 (a !tokens(1) / b !tokens(1) )
compute aa=!unquote(!a).
compute bb=!unquote(!b).
LIST aa bb.
!enddefine

define test2 (a !charend("/") / b !charend("/") )
compute aa=!a.
compute bb=!b.
LIST aa bb.
!enddefine

set mprint on printback on .
data list free / x.
begin data
1
end data.

test1 a=1 b=2.
test1 a='-.001' b='-1.2'.

test2 a=1 /b=2.
test2 a=-.001 / b= -1.2.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Negative values in macro

ANDRES ALBERTO BURGA LEON

Thank you very much David

I'll adapt this to my macro.

If y write somethingh like:

DEFINE test3 (a !TOKENS(1) / b !TOKENS(1))
COMPUTE aa=!a.
COMPUTE bb=!b.
LIST aa bb.
!ENDDEFINE.


SET MPRINT ON PRINTBACK ON.
DATA LIST FREE / x.
BEGIN DATA
1
END DATA.

It works fine with:

test3 a=0.4 b=2.,

but not with

test3 a=-0.2 b= -1.2.

So I must conclude that DEFINE test3 (a !TOKENS(1) / b !TOKENS(1)) doesn't woks for reading negative values as arguments in the macros.

Andres

Mg. Andrés Burga León
Coordinador de Análisis e Informática
Unidad de Medición de la Calidad Educativa
Ministerio de Educación del Perú
Calle El Comercio s/n (espalda del Museo de la Nación)
Lima 41
Perú
Teléfono 615-5840



David Marso <[hidden email]>
Enviado por: "SPSSX(r) Discussion" <[hidden email]>

18/03/2011 07:42 a.m.

Por favor, responda a
David Marso <[hidden email]>

Para
[hidden email]
cc
Asunto
Re: Negative values in macro





Greetings Andres,
Without getting into the idiosyncrasies of the MACRO parser or attempting to
explicate WTH constitutes a "TOKEN"  I provide the following 2 working
macros for you to ponder.  I leave it to you to adapt yours appropriately.
HTH, David

---
define test1 (a !tokens(1) / b !tokens(1) )
compute aa=!unquote(!a).
compute bb=!unquote(!b).
LIST aa bb.
!enddefine

define test2 (a !charend("/") / b !charend("/") )
compute aa=!a.
compute bb=!b.
LIST aa bb.
!enddefine

set mprint on printback on .
data list free / x.
begin data
1
end data.

test1 a=1 b=2.
test1 a='-.001' b='-1.2'.

test2 a=1 /b=2.
test2 a=-.001 / b= -1.2.


--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Using-Graph-Templates-tp3884884p3960512.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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: Negative values in macro

David Marso
Administrator
Use the !CHAREND variation to solve your problem.
You can either pass quoted negative values and use !UNQUOTE or use !CHAREND to delimit the arguments in the macro definition.  I find the quoted negatives and !UNQUOTE method to be simply inelegant!!!
In a nutshell, MACRO seems to have a half assed definition of a TOKEN.
Don't have the time to explain at the moment but it seems it treats - as a token in it's own right.
Maybe Jon Fry can enlighten us to the down and dirty on this one?  
He is the only one on the planet who *MIGHT* really know what is going on under the hood of that beast.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"