Hi, I am new here. Thanks in advance to anyone that answers my question. I want to make what what I believe is a simple macro but I can't get it to work. Here is a part of the syntax that I want to turn into a macro. I repeat these 3 lines of syntax about 20 times. The only things that change are the new variable name and the value of course7. How do I write a macro for this. Thanks.
compute MJ_INTENS_LANG_ARTS_6_1112 = 0. if (grade=6 AND course7='1000000') MJ_INTENS_LANG_ARTS_6_1112 = 1. execute. compute MJ_INTENS_READ_MC_6_1011=0. if (grade=6 AND course7 = '1000010') MJ_INTENS_READ_MC_6_1011=1. execute. compute MJ_LANG_ARTS_1_6_1011 = 0. if (grade=6 AND course7 = '1001010') MJ_LANG_ARTS_1_6_1011 = 1. execute. compute MJ_LANG_ARTS_1_ESOL_6_1011=0. if (grade=6 AND course7='1002000') MJ_LANG_ARTS_1_ESOL_6_1011=1. execute. |
Why won't a Do repeat work here?
Gene Maguin -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Brandon Sent: Thursday, December 20, 2012 9:00 AM To: [hidden email] Subject: Easy Macro Help Hi, I am new here. Thanks in advance to anyone that answers my question. I want to make what what I believe is a simple macro but I can't get it to work. Here is a part of the syntax that I want to turn into a macro. I repeat these 3 lines of syntax about 20 times. The only things that change are the new variable name and the value of course7. How do I write a macro for this. Thanks. compute MJ_INTENS_LANG_ARTS_6_1112 = 0. if (grade=6 AND course7='1000000') MJ_INTENS_LANG_ARTS_6_1112 = 1. execute. compute MJ_INTENS_READ_MC_6_1011=0. if (grade=6 AND course7 = '1000010') MJ_INTENS_READ_MC_6_1011=1. execute. compute MJ_LANG_ARTS_1_6_1011 = 0. if (grade=6 AND course7 = '1001010') MJ_LANG_ARTS_1_6_1011 = 1. execute. compute MJ_LANG_ARTS_1_ESOL_6_1011=0. if (grade=6 AND course7='1002000') MJ_LANG_ARTS_1_ESOL_6_1011=1. execute. -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Easy-Macro-Help-tp5717063.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 |
Administrator
|
In reply to this post by Brandon
1. First off the requirement for a MACRO is not obvious!
2. First pass you need to analyze your specific needs and isolate what changes and what remains constant. 3. Logical assignments are your friend. 4. DO REPEAT is much easier than a MACRO for where you need to go. 5. Get rid of those cycle wasting EXECUTE statements. 6. I avoid _ in variable names for numerous reasons and usually go with CamelCase eg MJ_INTENS_LANG_ARTS_6_1112 -> MjIntenseLangArts_6_1112 -- DO IF (grade EQ 6). + DO REPEAT v=MJ_INTENS_LANG_ARTS_6_1112 MJ_INTENS_READ_MC_6_1011 MJ_LANG_ARTS_1_6_1011 MJ_LANG_ARTS_1_ESOL_6_1011 /test='1000000' '1000010' '1001010' '1002000'. + COMPUTE v=(course7 EQ test). + END REPEAT. END IF. To get any macro to work like this will require you to 'parallel process' the two lists using !HEAD and !TAIL operators. If you want further help with MACRO you should post what you have attempted and read up in the FM under DEFINE !ENDDEFINE. Also research the archives of this list and you will find numerous examples others and myself have posted over the years. --
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 |