I
would like to put the variable label into a python variable
so that it appears on the Y axis.
The attached syntax has some data and runs the graphs. The only problem is that the variable name is used as teh Y-axis lable instead of the variable label. The red below shows where I think I need another Python variable. begin program. variables='Zscore1 to Zscore4' import spss,spssaux vList=spssaux.VariableDict().expand(variables) for vrbl in vList: spss.Submit(""" GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=year %(vrbl)s MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: year=col(source(s), name("year")) DATA: %(vrbl)s=col(source(s), name("%(vrbl)s")) SCALE: linear(dim(1), min(1993), max(2011)) GUIDE: axis(dim(1), label("year"), delta(1), start(1993)) SCALE: linear(dim(2), min(-3), max(3)) GUIDE: axis(dim(2), label("%(vrbl)s"), delta(1), start(-3)) ELEMENT: line(position(year*%(vrbl)s), missing.gap()) GUIDE: form.line(position(*,0)) END GPL."""%locals()) end program. -- Art Kendall Social Research Consultants for list.sps (2K) Download Attachment
Art Kendall
Social Research Consultants |
Here is a fragment that shows how to do
this. Create the variable dictionary and access the variable property.
This example just does the first variable.
begin program. import spss, spssaux vardict = spssaux.VariableDict() vrbl = vardict[0].VariableLabel end program. If the label might contain ", extra measures will be required. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Art Kendall <[hidden email]> To: [hidden email], Date: 06/10/2013 04:16 PM Subject: [SPSSX-L] Python Getting variable labels from spssaux.VariableDict Sent by: "SPSSX(r) Discussion" <[hidden email]> I would like to put the variable label into a python variable so that it appears on the Y axis. The attached syntax has some data and runs the graphs. The only problem is that the variable name is used as teh Y-axis lable instead of the variable label. The red below shows where I think I need another Python variable. begin program. variables='Zscore1 to Zscore4' import spss,spssaux vList=spssaux.VariableDict().expand(variables) for vrbl in vList: spss.Submit(""" GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=year %(vrbl)s MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: year=col(source(s), name("year")) DATA: %(vrbl)s=col(source(s), name("%(vrbl)s")) SCALE: linear(dim(1), min(1993), max(2011)) GUIDE: axis(dim(1), label("year"), delta(1), start(1993)) SCALE: linear(dim(2), min(-3), max(3)) GUIDE: axis(dim(2), label("%(vrbl)s"), delta(1), start(-3)) ELEMENT: line(position(year*%(vrbl)s), missing.gap()) GUIDE: form.line(position(*,0)) END GPL."""%locals()) end program. -- Art Kendall Social Research Consultants for list.sps (2K) Download Attachment Art Kendall View this message in context: Python Getting variable labels from spssaux.VariableDict Sent from the SPSSX Discussion mailing list archive at Nabble.com. |
I am trying to use Python to extract 2 things from the
dictionary.
In GGraph I would like to "plug in" 2 things for each variable. 1) the variable name -- vnam which goes several places 2) the variable label -- vlab which goes into a GUIDE specification GUIDE: axis(dim(2), label("%(vlab)s"), delta(1), start(-3)) in the syntax below I get this message File "<string>", line 8 there are two attached files for list.sps which almost works. It just does not have the variable label on the Y axis for list 2.sps which is my attempt to also get the variable label on the Y axis. I did replace all examples of "vrbl" with "vnam". * under <edit> <options> set aspect ratio to 2. data list list/ year(f4) zscore1 to zscore4 (4f6). begin data 1993 -.25 -2.08 . -1.33 1994 -.66 -1.73 . -1.19 1995 -.36 -1.65 . -1.19 1996 -.68 -1.37 . -.98 1997 -1.25 .07 . -.94 1998 -.79 .16 1.10 -.87 1999 .25 .59 1.48 -.49 2000 .13 1.03 1.38 -.45 2001 .17 1.00 1.27 -.14 2002 -.93 .15 .76 -.35 2003 -.36 .02 .46 -.35 2004 -.02 -.50 -.91 .21 2005 1.62 -.09 -.83 .53 2006 2.36 .51 -.83 .98 2007 1.69 .83 -.82 1.16 2008 .76 .85 -.73 1.47 2009 .23 .95 -.60 1.68 2010 -.67 .69 -.81 1.30 2011 -1.23 .57 -.93 .91 end data. variable labels Zscore1 'some set of words' Zscore2 'A second set of words' Zscore3 'third set of words' Zscore4 'words and words'. variable level year (nominal). begin program. variables='Zscore1 to Zscore4' import spss,spssaux vardict = spssaux.VariableDict() vList1=spssaux.VariableDict().expand(variables) for vnam in vList: vlab = vardict[0].VariableLabel spss.Submit(""" GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=year %(vnam)s MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: year=col(source(s), name("year")) DATA: %(vnam)s=col(source(s), name("%(vnam)s")) SCALE: linear(dim(1), min(1993), max(2011)) GUIDE: axis(dim(1), label("year"), delta(1), start(1993)) SCALE: linear(dim(2), min(-3), max(3)) GUIDE: axis(dim(2), label("%(vlab)s"), delta(1), start(-3)) ELEMENT: line(position(year*%(vnam)s), missing.gap()) GUIDE: form.line(position(*,0)) END GPL."""%locals()) end program. Art Kendall Social Research ConsultantsOn 6/10/2013 7:03 PM, Jon K Peck [via SPSSX Discussion] wrote: Here is a fragment that shows how to do this. Create the variable dictionary and access the variable property. This example just does the first variable.
Art Kendall
Social Research Consultants |
The spss.Submit line is indented one more
space than the line above.
Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Art Kendall <[hidden email]> To: [hidden email], Date: 06/11/2013 12:23 PM Subject: Re: [SPSSX-L] Python Getting variable labels from spssaux.VariableDict Sent by: "SPSSX(r) Discussion" <[hidden email]> I am trying to use Python to extract 2 things from the dictionary. In GGraph I would like to "plug in" 2 things for each variable. 1) the variable name -- vnam which goes several places 2) the variable label -- vlab which goes into a GUIDE specification GUIDE: axis(dim(2), label("%(vlab)s"), delta(1), start(-3)) in the syntax below I get this message File "<string>", line 8 spss.Submit(""" ^ IndentationError: unexpected indent there are two attached files for list.sps which almost works. It just does not have the variable label on the Y axis for list 2.sps which is my attempt to also get the variable label on the Y axis. I did replace all examples of "vrbl" with "vnam". * under <edit> <options> set aspect ratio to 2. data list list/ year(f4) zscore1 to zscore4 (4f6). begin data 1993 -.25 -2.08 . -1.33 1994 -.66 -1.73 . -1.19 1995 -.36 -1.65 . -1.19 1996 -.68 -1.37 . -.98 1997 -1.25 .07 . -.94 1998 -.79 .16 1.10 -.87 1999 .25 .59 1.48 -.49 2000 .13 1.03 1.38 -.45 2001 .17 1.00 1.27 -.14 2002 -.93 .15 .76 -.35 2003 -.36 .02 .46 -.35 2004 -.02 -.50 -.91 .21 2005 1.62 -.09 -.83 .53 2006 2.36 .51 -.83 .98 2007 1.69 .83 -.82 1.16 2008 .76 .85 -.73 1.47 2009 .23 .95 -.60 1.68 2010 -.67 .69 -.81 1.30 2011 -1.23 .57 -.93 .91 end data. variable labels Zscore1 'some set of words' Zscore2 'A second set of words' Zscore3 'third set of words' Zscore4 'words and words'. variable level year (nominal). begin program. variables='Zscore1 to Zscore4' import spss,spssaux vardict = spssaux.VariableDict() vList1=spssaux.VariableDict().expand(variables) for vnam in vList: vlab = vardict[0].VariableLabel spss.Submit(""" GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=year %(vnam)s MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: year=col(source(s), name("year")) DATA: %(vnam)s=col(source(s), name("%(vnam)s")) SCALE: linear(dim(1), min(1993), max(2011)) GUIDE: axis(dim(1), label("year"), delta(1), start(1993)) SCALE: linear(dim(2), min(-3), max(3)) GUIDE: axis(dim(2), label("%(vlab)s"), delta(1), start(-3)) ELEMENT: line(position(year*%(vnam)s), missing.gap()) GUIDE: form.line(position(*,0)) END GPL."""%locals()) end program. Art Kendall Social Research Consultants On 6/10/2013 7:03 PM, Jon K Peck [via SPSSX Discussion] wrote: Here is a fragment that shows how to do this. Create the variable dictionary and access the variable property. This example just does the first variable. begin program. import spss, spssaux vardict = spssaux.VariableDict() vrbl = vardict[0].VariableLabel end program. If the label might contain ", extra measures will be required. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Art Kendall <[hidden email]> To: [hidden email], Date: 06/10/2013 04:16 PM Subject: [SPSSX-L] Python Getting variable labels from spssaux.VariableDict Sent by: "SPSSX(r) Discussion" <[hidden email]> I would like to put the variable label into a python variable so that it appears on the Y axis. The attached syntax has some data and runs the graphs. The only problem is that the variable name is used as teh Y-axis lable instead of the variable label. The red below shows where I think I need another Python variable. begin program. variables='Zscore1 to Zscore4' import spss,spssaux vList=spssaux.VariableDict().expand(variables) for vrbl in vList: spss.Submit(""" GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=year %(vrbl)s MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: year=col(source(s), name("year")) DATA: %(vrbl)s=col(source(s), name("%(vrbl)s")) SCALE: linear(dim(1), min(1993), max(2011)) GUIDE: axis(dim(1), label("year"), delta(1), start(1993)) SCALE: linear(dim(2), min(-3), max(3)) GUIDE: axis(dim(2), label("%(vrbl)s"), delta(1), start(-3)) ELEMENT: line(position(year*%(vrbl)s), missing.gap()) GUIDE: form.line(position(*,0)) END GPL."""%locals()) end program. -- Art Kendall Social Research Consultants for list.sps (2K) Download Attachment Art Kendall
View this message in context: Python Getting variable labels from spssaux.VariableDict Sent from the SPSSX Discussion mailing list archive at Nabble.com. If you reply to this email, your message will be added to the discussion below: http://spssx-discussion.1045642.n5.nabble.com/Python-Getting-variable-labels-from-spssaux-VariableDict-tp5720662p5720663.html To start a new topic under SPSSX Discussion, email [hidden email] To unsubscribe from SPSSX Discussion, click here. NAML for list2.sps (2K) Download Attachment for list.sps (2K) Download Attachment Art Kendall View this message in context: Re: Python Getting variable labels from spssaux.VariableDict Sent from the SPSSX Discussion mailing list archive at Nabble.com. |
Free forum by Nabble | Edit this page |