CONTENTS DELETED
The author has deleted this message.
|
If you are vaguely familiar with Python (which I believe you are) you perhaps ought to be looking at setting this up in python, which would be much, much easier to do. If by "the length of the input" you mean the number of elements (space and comma delimited - as the alternative length of the string would be trivial to calculate using !LENGHT). See below demo which shows how to get the first (head), last (tail) and count of all the elements provided in the "options" parameter: /***********************************************/ define !test(options= !cmdend) title headOptions=!head(!options). !let !counter1=!blanks(0) !do !i !in (!options) !let !counter1=!concat(!counter1,!blanks(1)) !let !nbOptions=!len(!counter1) !doend title nbOptions=!nbOptions. !let !tailOptions=!options !do !i =2 !to !nbOptions !let !tailOptions=!tail(!tailOptions) !doend title tailOptions=!tailOptions. !enddefine. /***********************************************/ !test options= 1.0 2.0 3.0. !test options= 1.0 2.0 3.0 4.0 145,140. /* Notice how "145,140" is interpreted as 3 elements and perhaps not one as might be intended with comma being used as a thousand separator */. Now the equivalent of this in python would simply be: /***********************************************/ begin program. def test(options): nbOptions=len(options.split()) firstOptions=options.split()[0] lastOptions=options.split()[-1] print "nbOptions=",nbOptions print "firstOptions=",firstOptions print "lastOptions=",lastOptions test("1.0 2.0 3.0") test("1.0 2.0 3.0 4.0 145,140") # correctly interprets 145,140 as a single value (and not 3 values), if indeed that is how you want to interpret comma between numbers end program. /***********************************************/ On 12 February 2015 at 03:58, Alex Huang <[hidden email]> wrote: Hi, |
CONTENTS DELETED
The author has deleted this message.
|
If you’re thinking of R and SPSS Juanjo Medina (Manchester) just sent me this, which may be a source of useful advice: http://www.r-bloggers.com/translate2r-and-translatespss2r-implanting-spss-functionality-into-r/ John F Hall (Mr) [Retired academic survey researcher] Email: [hidden email] Website: www.surveyresearch.weebly.com SPSS start page: www.surveyresearch.weebly.com/1-survey-analysis-workshop From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Alex Huang Dear Jignesh Sutar, Terribly sorry that I am not familiar with Python but I am experienced with R (I think I am quite familiar, at least I would prefer R than Python). Your suggestion makes me think of an interesting alternative: Is it possible to set up R essentials in SPSS 19 32bit? If it is possible, I would do it in R as I am familiar with what I want to do in my previous question(vector[1], length(vector) vector[length(vector)]). Thanks much, Alex 2015-02-12 15:36 GMT+08:00 Jignesh Sutar <[hidden email]>: If you are vaguely familiar with Python (which I believe you are) you perhaps ought to be looking at setting this up in python, which would be much, much easier to do. If by "the length of the input" you mean the number of elements (space and comma delimited - as the alternative length of the string would be trivial to calculate using !LENGHT). See below demo which shows how to get the first (head), last (tail) and count of all the elements provided in the "options" parameter: /***********************************************/ define !test(options= !cmdend) title headOptions=!head(!options). !let !counter1=!blanks(0) !do !i !in (!options) !let !counter1=!concat(!counter1,!blanks(1)) !let !nbOptions=!len(!counter1) !doend title nbOptions=!nbOptions. !let !tailOptions=!options !do !i =2 !to !nbOptions !let !tailOptions=!tail(!tailOptions) !doend title tailOptions=!tailOptions. !enddefine. /***********************************************/ !test options= 1.0 2.0 3.0. !test options= 1.0 2.0 3.0 4.0 145,140. /* Notice how "145,140" is interpreted as 3 elements and perhaps not one as might be intended with comma being used as a thousand separator */. Now the equivalent of this in python would simply be: /***********************************************/ begin program. def test(options): nbOptions=len(options.split()) firstOptions=options.split()[0] lastOptions=options.split()[-1] print "nbOptions=",nbOptions print "firstOptions=",firstOptions print "lastOptions=",lastOptions test("1.0 2.0 3.0") test("1.0 2.0 3.0 4.0 145,140") # correctly interprets 145,140 as a single value (and not 3 values), if indeed that is how you want to interpret comma between numbers end program. /***********************************************/ On 12 February 2015 at 03:58, Alex Huang <[hidden email]> wrote: Hi, ===================== 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 |
In reply to this post by Alex Huang
Yes, it is certainly possible to set up
the R Essentials for Statistics 19. See the section for R Essentials
on this page.
https://www.ibm.com/developerworks/community/wikis/home?lang=en#/wiki/We70df3195ec8_4f95_9773_42e448fa9029/page/Downloads%20for%20IBM%C2%AE%20SPSS%C2%AE%20Statistics You will need to install the corresponding back version of R to go with this, but you can have multiple versions of R installed if needed. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Alex Huang <[hidden email]> To: [hidden email] Date: 02/12/2015 09:41 PM Subject: Re: [SPSSX-L] SPSS macro parameters Sent by: "SPSSX(r) Discussion" <[hidden email]> Dear Jignesh Sutar, Terribly sorry that I am not familiar with Python but I am experienced with R (I think I am quite familiar, at least I would prefer R than Python). Your suggestion makes me think of an interesting alternative: Is it possible to set up R essentials in SPSS 19 32bit? If it is possible, I would do it in R as I am familiar with what I want to do in my previous question(vector[1], length(vector) vector[length(vector)]). Thanks much, Alex 2015-02-12 15:36 GMT+08:00 Jignesh Sutar <jsutar@...>: If you are vaguely familiar with Python (which I believe you are) you perhaps ought to be looking at setting this up in python, which would be much, much easier to do. If by "the length of the input" you mean the number of elements (space and comma delimited - as the alternative length of the string would be trivial to calculate using !LENGHT). See below demo which shows how to get the first (head), last (tail) and count of all the elements provided in the "options" parameter: /***********************************************/ define !test(options= !cmdend) title headOptions=!head(!options). !let !counter1=!blanks(0) !do !i !in (!options) !let !counter1=!concat(!counter1,!blanks(1)) !let !nbOptions=!len(!counter1) !doend title nbOptions=!nbOptions. !let !tailOptions=!options !do !i =2 !to !nbOptions !let !tailOptions=!tail(!tailOptions) !doend title tailOptions=!tailOptions. !enddefine. /***********************************************/ !test options= 1.0 2.0 3.0. !test options= 1.0 2.0 3.0 4.0 145,140. /* Notice how "145,140" is interpreted as 3 elements and perhaps not one as might be intended with comma being used as a thousand separator */. Now the equivalent of this in python would simply be: /***********************************************/ begin program. def test(options): nbOptions=len(options.split()) firstOptions=options.split()[0] lastOptions=options.split()[-1] print "nbOptions=",nbOptions print "firstOptions=",firstOptions print "lastOptions=",lastOptions test("1.0 2.0 3.0") test("1.0 2.0 3.0 4.0 145,140") # correctly interprets 145,140 as a single value (and not 3 values), if indeed that is how you want to interpret comma between numbers end program. /***********************************************/ On 12 February 2015 at 03:58, Alex Huang <alexhuangah1@...> wrote: Hi, I am designing a SPSS macro which takes several inputs as parameters. I have the following: DEFINE !optionAN (var = TOKENS(1), options = !CMDEND) in which I would like to take the first parameter as var, and all the others as options. I accept various number of inputs for options here. !optionAN var = Q1 options = 35 8887 8888. !optionAN var = Q2 options = 4 8888. I would like to ask if it is possible to find out: 1. the value of the first or the last inputs for options, 2. the length of the input, inside the macro so that I can input the values as parameters? DEFINE !optionAN (var = TOKENS(1), options = !CMDEND) VECTOR var(!length(options)). VECTOR v = concat(!var, "_1") TO !concat(!var, "_99"). LOOP #i = 1 to (!length(options)). COMPUTE var(#i) = v(#i). END LOOP. !ENDDEFINE. Thank you. Note: I have not yet test the code. I am not sure whether it is correct to write (var = TOKENS(1), options = !CMDEND) there. Please correct it if I have any mistakes. Thanks much, Alex -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/SPSS-macro-parameters-tp5728654.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@... (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 LISTSERV@... (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 |
Administrator
|
In reply to this post by Alex Huang
FWIW, the , in the DEFINE line needs to be replaced by a / ! ---------------------------------------------------------------
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?" |
In reply to this post by Alex Huang
At 10:58 PM 2/11/2015, Alex Huang wrote:
>I have the following: > >DEFINE !optionAN (var = TOKENS(1), options = !CMDEND) You mean, I think, DEFINE !optionAN (var = !TOKENS(1)/ options = !CMDEND) i.e., adding "!" before "TOKENS(1)", and putting "/" instead of "," after it. >I would like to take the first parameter as var [or rather, macro >value !var], and all the others as options [or macro value >!options]. I accept various number of inputs for options here. > >!optionAN var = Q1 options = 35 8887 8888. >!optionAN var = Q2 options = 4 8888. > >I would like to ask if it is possible to find out: > >1. the value of the first or the last inputs for options, >2. the length of the input, This depends on what you mean by the 'first' and 'last' inputs. If you mean the first and last characters, they are respectively !LET !FrstChr = (!SUBSTR(!options,1,1)) and !LET !LastChr = (!SUBSTR(!options,!LENGTH(!options),1)) If you mean the first and last *tokens*, they are respectively !LET !FrstTok = !HEAD(!options) and, for the last token, a slightly longer calculation (David Marso, or somebody, may know a better way): !DO !i !IN (!options) !LET !LastTok = !i !DOEND Then, using ECHO commands within the macro to print values, you have the following. (The macro is defined in the Appendix at the end of this note): * Demo I: ... . * Test calls, from original posting: ... . * ... . !optionAN var = Q1 options = 35 8887 8888. var =Q1 options=35 8887 8888 Within options: First char =3 Last char =8 First token=35 Last token=8888 * ... . !optionAN var = Q2 options = 4 8888. var =Q2 options=4 8888 Within options: First char =4 Last char =8 First token=4 Last token=8888 But it looks like that's not exactly what you want to do. You say you want, >DEFINE !optionAN (var = TOKENS(1), options = !CMDEND) >VECTOR var(!length(options)). >VECTOR v = concat(!var, "_1") TO !concat(!var, "_99"). >LOOP #i = 1 to (!length(options)). >COMPUTE var(#i) = v(#i). >END LOOP. >!ENDDEFINE. What is the idea here? You're defining a vector whose root name is "var", and which has as many member as there are characters in "options", and then you're assigning its values from the corresponding members of the vector whose root name is given by parameter "var". (Sorry, this is confusing, since you use "var" to mean two different things.) And the only thing you use from "options" is its length; why not just pass the integer value as a parameter? So, clearly I'm not understanding what you're trying to do. Can you explain a little further? -Best wishes, Richard Ristow ==================== APPENDIX: Test code ==================== * C:\Documents and Settings\Richard\My Documents . * \Technical\spssx-l\Z-2015\ . * 2011-02-11 Huang-SPSS macro parameters.SPS . * In response to posting . * Date: Wed, 11 Feb 2015 20:58:02 -0700 . * From: Alex Huang <[hidden email]> . * Subject: SPSS macro parameters . * To: [hidden email] . * "I have the following: . * . * DEFINE !optionAN (var = TOKENS(1), options = !CMDEND) . * . * in which I would like to take the first parameter as var [or . * rather, !var], and all the others as options [or !options]. I . * accept various number of inputs for options here. . * . * !optionAN var = Q1 options = 35 8887 8888. . * !optionAN var = Q2 options = 4 8888. . * . * "I would like to ask if it is possible to find out: . * . * 1. the value of the first or the last inputs for options, . * 2. the length of the input" . * Test I: First and last inputs, by two definitions: . DEFINE !optionAN (var = !TOKENS(1)/ options = !CMDEND) . ECHO ' '. . ECHO !QUOTE(!CONCAT('var =',!var)). . ECHO !QUOTE(!CONCAT('options=',!options)). !LET !FrstChr = (!SUBSTR(!options,1,1)) !LET !LastChr = (!SUBSTR(!options,!LENGTH(!options),1)) !LET !FrstTok = !HEAD(!options) !DO !i !IN (!options) !LET !LastTok = !i !DOEND . ECHO 'Within options:'. . ECHO !QUOTE(!CONCAT('First char =',!FrstChr)). . ECHO !QUOTE(!CONCAT('Last char =',!LastChr)). . ECHO !QUOTE(!CONCAT('First token=',!FrstTok)). . ECHO !QUOTE(!CONCAT('Last token=',!LastTok)). !ENDDEFINE. * Demo I: ... . * Test calls, from original posting: ... . * ... . !optionAN var = Q1 options = 35 8887 8888. * ... . !optionAN var = Q2 options = 4 8888. ===================== 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 |
CONTENTS DELETED
The author has deleted this message.
|
Hi, Alex, Doing calculation with macro variables is a long journey as macro language was not designed in this way. But addition is manageable. You could find here detailed explanations and examples of addition and more complex operations: Best regards, Anton Balabanov 16.02.2015, 14:05, "Alex Huang" <[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 |
Anton,
Do the documents you link to have this one way to do subtraction? define !subtract(!pos= !token(1) /!pos= !token(1)) !let !x= !blanks(!1) !let !y= !blanks(!2) !let !result= !len(!substr(!x, !len(!conc(!y,' ')))) echo !quote(!result). !enddefine. !subtract 11 6. 16.02.2015 14:18, Anton Balabanov
пишет:
===================== 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 |
Administrator
|
The following should work as well (no need to set up !x and !y). No SPSS on this box. define !subtract(!pos= !token(1) /!pos= !token(1)) !let !result= !len(!substr(!blanks(!1), !len(!conc(!blanks(!2),' ')))) echo !quote(!result). !enddefine. !subtract 11 6.
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?" |
In reply to this post by Alex Huang
The latter, by Paul H. Cook, 2002, does. It suggests method even for integer division and modulus, for braves :)
> Anton, > > Do the documents you link to have this one way to do subtraction? > > define !subtract(!pos= !token(1) /!pos= !token(1)) > > !let !x= !blanks(!1) > > !let !y= !blanks(!2) > > !let !result= !len(!substr(!x, !len(!conc(!y,' ')))) > > echo !quote(!result). > > !enddefine. > > !subtract 11 6. > > 16.02.2015 14:18, Anton Balabanov > пишет: > >> Hi, Alex, >> >> Doing calculation with macro variables is a long journey as >> macro language was not designed in this way. But addition is >> manageable. >> >> You could find here detailed explanations and examples of >> addition and more complex operations: >> >> http://spsstools.net/MacroTutorial.htm#DoingArithmetic >> >> http://spsstools.net/Macros/MacrosVariable/ArithmeticWithMacroVariables.sps >> >> Best regards, >> >> Anton Balabanov ===================== 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 |
In reply to this post by Alex Huang
Maybe I did not understand your post. But it seems that you could just use the MULT RESPONSE procedure.
Depending what you are trying to do use MULT RESPONSE and crosstab a set by itself or treat the first response variable as a single variable and the rest of the variables as a set; then cross tab the variable by the set. It is also likely that you could use TABLES or CTABLES without writing any macros.
Art Kendall
Social Research Consultants |
CONTENTS DELETED
The author has deleted this message.
|
Administrator
|
Suggestions:
1. Get rid of the EXECUTE commands. 2. Add a BLANK line between the macros. 3. Add comments to the code so it is easily understandable with respect to intention, assumptions, side effects.... /* This macro does blah blah blah. It requires the following blah blah blah as INPUT. The first blah blah blah denotes ... the second blah blah blah..... It creates the following <output> It has the following side blah blah blah effects on the data . If you don't intend to actually create any new variables in the data file consider using TEMPORARY. Then you can delete the DELETE VARIABLES command and indeed ALL execute statements. After you comment the code, I may have further suggestions. At this point I don't have the time to spend to try to guess why/what you are doing/trying to do.
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?" |
Free forum by Nabble | Edit this page |