Re: Can I add a Graph Title with a Macro?

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

Re: Can I add a Graph Title with a Macro?

Jon Peck
I hate macro, but I don't like to see people suffer.

Here's a nonmacro Python equivalent (untested).  An expression like %(group1)s means to substitute the text in the variable group1 at that point in the literal, so here that would expand to g1.

begin program.
import spss, sys
def dograph():
    dependent = sys.argv[1]
    group1 = sys.argv[2]
    group2 = sys.argv[3]
    spss.Submit("""GRAPH
  /SCATTERPLOT(OVERLAY)= %(group2)s WITH %(group1)s_Frequency%(group2)s_Frequency) (pair)
  /MISSING=LISTWISE
  /TITLE="Normalized Distribution of %(dependent)s by %(group1)s and %(group2)s" """ %locals())
end program.
  
SPSSINC PROGRAM dograph z g1 g2.



On Thu, Jan 3, 2019 at 7:56 PM Dates, Brian <[hidden email]> wrote:

Thanks, Jon! More study of macros for me!


Brian

From: Jon Peck <[hidden email]>
Sent: Thursday, January 3, 2019 9:31:48 PM
To: Dates, Brian
Cc: SPSS List
Subject: Re: [SPSSX-L] Can I add a Graph Title with a Macro?
 
  /TITLE=!quote(!concat("Normalized Distribution of ", !Dependent,  " by ", !Group1, " and ", !Group2)) .

On Thu, Jan 3, 2019 at 7:17 PM Dates, Brian <[hidden email]> wrote:

I have a macro which produces normalized plots of a continuous variable by two attributes of a dichotomous variable, (e.g., GAF by treatment and comparison). The macro variables clearly work in the scatterplot overlay section, but not in the title (highlighted). What am I missing? Here's the graph command with the macro call line below. I've tried lots of macro commands, e.g., !quote, !unquote, etc. The macro is !name.  I'd like to use the existing macro rather than add another just for use in the title. Thanks.


GRAPH
  /SCATTERPLOT(OVERLAY)=!Group1 !Group2 WITH !concat(!Group1,"_Frequency") !concat(!Group2,"_Frequency") (pair)
  /MISSING=LISTWISE
  /TITLE='Normalized Distribution of !Dependent by !Group1 and !Group2' .

!ENDDEFINE.
!name Dependent=GAF_Post groupvar=group Group1=Comparison Group2=Treatment Groupval1=0 Groupval2=1 FILE='c:/spss data/Effects of a Supported Employment Program Data Set.sav' .

Brian

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


--
Jon K Peck
[hidden email]



--
Jon K Peck
[hidden email]

===================== 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: Can I add a Graph Title with a Macro?

bdates

Thanks again, Jon. I've used both, and I'm going to go with the Python equivalent. It's cleaner throughout the entire computation process, which precedes the graphing. I hadn't thought of that.


Brian

From: Jon Peck <[hidden email]>
Sent: Thursday, January 3, 2019 10:16:53 PM
To: Dates, Brian
Cc: SPSS List
Subject: Re: [SPSSX-L] Can I add a Graph Title with a Macro?
 
I hate macro, but I don't like to see people suffer.

Here's a nonmacro Python equivalent (untested).  An expression like %(group1)s means to substitute the text in the variable group1 at that point in the literal, so here that would expand to g1.

begin program.
import spss, sys
def dograph():
    dependent = sys.argv[1]
    group1 = sys.argv[2]
    group2 = sys.argv[3]
    spss.Submit("""GRAPH
  /SCATTERPLOT(OVERLAY)= %(group2)s WITH %(group1)s_Frequency%(group2)s_Frequency) (pair)
  /MISSING=LISTWISE
  /TITLE="Normalized Distribution of %(dependent)s by %(group1)s and %(group2)s" """ %locals())
end program.
  
SPSSINC PROGRAM dograph z g1 g2.



On Thu, Jan 3, 2019 at 7:56 PM Dates, Brian <[hidden email]> wrote:

Thanks, Jon! More study of macros for me!


Brian

From: Jon Peck <[hidden email]>
Sent: Thursday, January 3, 2019 9:31:48 PM
To: Dates, Brian
Cc: SPSS List
Subject: Re: [SPSSX-L] Can I add a Graph Title with a Macro?
 
  /TITLE=!quote(!concat("Normalized Distribution of ", !Dependent,  " by ", !Group1, " and ", !Group2)) .

On Thu, Jan 3, 2019 at 7:17 PM Dates, Brian <[hidden email]> wrote:

I have a macro which produces normalized plots of a continuous variable by two attributes of a dichotomous variable, (e.g., GAF by treatment and comparison). The macro variables clearly work in the scatterplot overlay section, but not in the title (highlighted). What am I missing? Here's the graph command with the macro call line below. I've tried lots of macro commands, e.g., !quote, !unquote, etc. The macro is !name.  I'd like to use the existing macro rather than add another just for use in the title. Thanks.


GRAPH
  /SCATTERPLOT(OVERLAY)=!Group1 !Group2 WITH !concat(!Group1,"_Frequency") !concat(!Group2,"_Frequency") (pair)
  /MISSING=LISTWISE
  /TITLE='Normalized Distribution of !Dependent by !Group1 and !Group2' .

!ENDDEFINE.
!name Dependent=GAF_Post groupvar=group Group1=Comparison Group2=Treatment Groupval1=0 Groupval2=1 FILE='c:/spss data/Effects of a Supported Employment Program Data Set.sav' .

Brian

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


--
Jon K Peck
[hidden email]



--
Jon K Peck
[hidden email]

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