|
Dear all,
My macro (below) is not working. It seems that 'insert file' doesn't function within a macro because the syntax that is printed in the viewer actually deviates from the contents of the little syntax file that's inserted (I deliberately kept it to trace the source of the problem). It seems this goes only for the first 2 variables of the original data. If I manually rerun the syntax that had been inserted during the macro expansion, I finally get the desired result. Does anybody please have any clue why it's not working as it should? Is this a bug or am I overlooking something? TIA! Ruben van den Berg Methodologist TNS NIPO P: +31 20 522 5738 cd 'c:\temp'. datas clo all. *create fake data. data list free/id. begin data 1 2 3 end data. do rep v=var_a var_b var_c. comp v=rnd(rv.uni(.5,2.5)). end rep. var lab id'respondent number'var_a'gender'var_b'income'var_c'political_pref'. exe. datas nam d1. *macro definition. define !rennum(dat=!tok(1)) !if (!dat !ne '') !then set mpr on. DATASET DECLARE vars. OMS /SELECT TABLES /IF COMMANDS = ["File Information"] SUBTYPES = ["Variable Information"] /DESTINATION FORMAT = SAV NUMBERED = TableNumber_ OUTFILE = vars VIEWER = NO /TAG = "vars". disp var. omsend tag=['vars']. datas act vars. ren var var1=variable. sav out 'varlabs.sav' /kee variable to WriteFormat. str s1(a256). str s2 (a256). comp s1=con("ren var ",rtr(variable),"= v",ltr(str(position,f4)),"."). comp s2=con("var lab v",ltr(str(position,f4)),'"',rtr(variable),' % ',rtr(label),'".'). wri out '$rennum.sps'/s1. wri out '$rennum.sps'/s2. exe. datas clo vars. datas act !dat. ins fil='$rennum.sps'. *era fil='$rennum.sps'. !ifend !enddefine. *macro call. !rennum dat=d1. New Windows 7: Find the right PC for you. Learn more. |
|
Administrator
|
Allow me to comment.
First off I am using a PRE INSERT version of SPSS (11.5)... Perhaps try INCLUDE instead. <RANT> This sort of writing syntax has been deprecated for several years now. Don't get me wrong. I was the first one to create this type of Rube Goldberg gibberish when there were no other options (say about 15 years ago in the mid 90's). Raynald Lavesque then went all "hammer on nail" with the technique and now it seems to have taken on a life of it's own. With scripts and Python available I can not think of any good reason to build code like this and INSERT it. OTOH, try INCLUDE and see if that helps. In passing, you do NOT do yourself ANY favors at all in your consistent 3 letter abbreviations of SPSS commands. I know that COM means COMPUTE and CON means CONCAT etc... but you make people work WAY TOO HARD to understand the intentions of your code. USE FULLY SPELLED OUT COMMANDS and you will be very happy later when you are able to understand WTF it is that the program is supposed to do without taking 20 minutes to decipher your own programing 3 years from now. Your boss will be very happy when your successor is able to understand the code you have left behind after you win the lottery and retire to the Bahamas, or god forbid you get hit by a bus. Since your abbreviated code is virtually impossible to interpret without spending a inordinate amount of time reparsing it and incurring a severe headache in the process, I will defer to someone else who is willing to spend way too much time to figure out WTH you are actually trying to do. Which brings me to the next part of my rant. How about describing WHAT you are attempting to achieve rather than.... This doesn't work!! WHY??? Maybe there are better ways of achieving what you want to do than this Micky Mouse indirect Rube Goldberg-esque syntax-generating-syntax-gobbly-gook-monstrosity ..... I'M ALLOWED TO CALL IT THAT BECAUSE I INVENTED THE TECHNIQUE! -There is SO MUCH code I posted on this list YEARS ago that I wish I had never ever posted!!!- I still see the floaters rise to the surface every once in awhile- SHIT like... SAVE OUTFILE blah1. FLIP. WRITE OUTFILE blah1... /CASE_LBL . DATA LIST FILE =blah2/VARNAME ... SORT CASES BY VARNAME . FLIP. ADD FILES FILE * / FILE Blah1 ... To alphabetize a data dictionary. The sorry bastard didn't tell me he had 12 million cases ;-)))) LMFAO! Do you see the problem with the approach? Well, the WRITE Outfile approach to syntax is the same sort of possibly BADLY behaved code that will bite you on the ass eventually. </RANT> Hope this helps. I don't mean to be severe with you, Call it Tough Love.. Now go rewrite your code so people can understand WTF you are trying to do. ----------------------- On Tue, 27 Apr 2010 11:52:53 +0000, Ruben van den Berg <[hidden email]> wrote: > >Dear all, > > > >My macro (below) is not working. It seems that 'insert file' doesn't function within a macro because the syntax that is printed in the viewer actually deviates from the contents of the little syntax file that's inserted (I deliberately kept it to trace the source of the problem). It seems this goes only for the first 2 variables of the original data. If I manually rerun the syntax that had been inserted during the macro expansion, I finally get the desired result. Does anybody please have any clue why it's not working as it should? Is this a bug or am I overlooking something? > > > >TIA! > > >Ruben van den Berg >Methodologist >TNS NIPO >E: [hidden email] >P: +31 20 522 5738 >I: www.tns-nipo.com > > >cd 'c:\temp'. >datas clo all. > > > >*create fake data. > > > >data list free/id. >begin data >1 2 3 >end data. >do rep v=var_a var_b var_c. >comp v=rnd(rv.uni(.5,2.5)). >end rep. >var lab id'respondent number'var_a'gender'var_b'income'var_c'political_pref'. >exe. >datas nam d1. > > > >*macro definition. > > > >define !rennum(dat=!tok(1)) >!if (!dat !ne '') !then >set mpr on. >DATASET DECLARE vars. >OMS > /SELECT TABLES > /IF COMMANDS = ["File Information"] > SUBTYPES = ["Variable Information"] > /DESTINATION FORMAT = SAV NUMBERED = TableNumber_ > OUTFILE = vars > VIEWER = NO > /TAG = "vars". >disp var. >omsend tag=['vars']. >datas act vars. >ren var var1=variable. >sav out 'varlabs.sav' >/kee variable to WriteFormat. >str s1(a256). >str s2 (a256). >comp s1=con("ren var ",rtr(variable),"= v",ltr(str(position,f4)),"."). >comp s2=con("var lab v",ltr(str(position,f4)),'"',rtr(variable),' % >wri out '$rennum.sps'/s1. >wri out '$rennum.sps'/s2. >exe. >datas clo vars. >datas act !dat. >ins fil='$rennum.sps'. >*era fil='$rennum.sps'. >!ifend >!enddefine. > > > >*macro call. > > > >!rennum dat=d1. > > >_________________________________________________________________ >New Windows 7: Find the right PC for you. Learn more. >http://windows.microsoft.com/shop ===================== 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
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?" |
|
Dear David,
Thanks a lot for sharing your opinion with us. I agree that abbreviating code may be a bad habit when you post it to the list. However, since I have to write a lot of (basic) syntax, avoiding unnecessary keystrokes is a real issue for me. As far as the other recommendations are concerned, I don't really have to explain to you why not every single SPSS user writes perfect scripts, Python code, macros or even (basic) syntax, do I? You seemed slightly frustrated because of this fact of life... Best regards, Ruben van den Berg Methodologist TNS NIPO P: +31 20 522 5738 > Date: Wed, 28 Apr 2010 01:35:02 -0400 > From: [hidden email] > Subject: Re: Can I INSERT FILE in a macro? > To: [hidden email] > > Allow me to comment. > First off I am using a PRE INSERT version of SPSS (11.5)... > Perhaps try INCLUDE instead. > <RANT> > This sort of writing syntax has been deprecated for several years now. > Don't get me wrong. I was the first one to create this type of Rube > Goldberg gibberish when there were no other options (say about 15 years ago > in the mid 90's). Raynald Lavesque then went all "hammer on nail" with the > technique and now it seems to have taken on a life of it's own. With > scripts and Python available I can not think of any good reason to build > code like this and INSERT it. OTOH, try INCLUDE and see if that helps. > In passing, you do NOT do yourself ANY favors at all in your consistent 3 > letter abbreviations of SPSS commands. I know that COM means COMPUTE and > CON means CONCAT etc... but you make people work WAY TOO HARD to understand > the intentions of your code. USE FULLY SPELLED OUT COMMANDS and you will be > very happy later when you are able to understand WTF it is that the program > is supposed to do without taking 20 minutes to decipher your own programing > 3 years from now. Your boss will be very happy when your successor is able > to understand the code you have left behind after you win the lottery and > retire to the Bahamas, or god forbid you get hit by a bus. > Since your abbreviated code is virtually impossible to interpret without > spending a inordinate amount of time reparsing it and incurring a severe > headache in the process, I will defer to someone else who is willing to > spend way too much time to figure out WTH you are actually trying to do. > Which brings me to the next part of my rant. How about describing WHAT you > are attempting to achieve rather than.... This doesn't work!! WHY??? > Maybe there are better ways of achieving what you want to do than this Micky > Mouse indirect Rube Goldberg-esque > syntax-generating-syntax-gobbly-gook-monstrosity ..... I'M ALLOWED TO CALL > IT THAT BECAUSE I INVENTED THE TECHNIQUE! -There is SO MUCH code I posted on > this list YEARS ago that I wish I had never ever posted!!!- I still see the > floaters rise to the surface every once in awhile- > SHIT like... > SAVE OUTFILE blah1. > FLIP. > WRITE OUTFILE blah1... /CASE_LBL . > DATA LIST FILE =blah2/VARNAME ... > SORT CASES BY VARNAME . > FLIP. > ADD FILES FILE * / FILE Blah1 ... > To alphabetize a data dictionary. > The sorry bastard didn't tell me he had 12 million cases ;-)))) LMFAO! > Do you see the problem with the approach? > Well, the WRITE Outfile approach to syntax is the same sort of possibly > BADLY behaved code that will bite you on the ass eventually. > </RANT> > Hope this helps. I don't mean to be severe with you, Call it Tough Love.. > Now go rewrite your code so people can understand WTF you are trying to do. > > ----------------------- > > > On Tue, 27 Apr 2010 11:52:53 +0000, Ruben van den Berg > <[hidden email]> wrote: > > > > >Dear all, > > > > > > > >My macro (below) is not working. It seems that 'insert file' doesn't > function within a macro because the syntax that is printed in the viewer > actually deviates from the contents of the little syntax file that's > inserted (I deliberately kept it to trace the source of the problem). It > seems this goes only for the first 2 variables of the original data. If I > manually rerun the syntax that had been inserted during the macro expansion, > I finally get the desired result. Does anybody please have any clue why it's > not working as it should? Is this a bug or am I overlooking something? > > > > > > > >TIA! > > > > > >Ruben van den Berg > >Methodologist > >TNS NIPO > >E: [hidden email] > >P: +31 20 522 5738 > >I: www.tns-nipo.com > > > > > >cd 'c:\temp'. > >datas clo all. > > > > > > > >*create fake data. > > > > > > > >data list free/id. > >begin data > >1 2 3 > >end data. > >do rep v=var_a var_b var_c. > >comp v=rnd(rv.uni(.5,2.5)). > >end rep. > >var lab id'respondent number'var_a'gender'var_b'income'var_c'political_pref'. > >exe. > >datas nam d1. > > > > > > > >*macro definition. > > > > > > > >define !rennum(dat=!tok(1)) > >!if (!dat !ne '') !then > >set mpr on. > >DATASET DECLARE vars. > >OMS > > /SELECT TABLES > > /IF COMMANDS = ["File Information"] > > SUBTYPES = ["Variable Information"] > > /DESTINATION FORMAT = SAV NUMBERED = TableNumber_ > > OUTFILE = vars > > VIEWER = NO > > /TAG = "vars". > >disp var. > >omsend tag=['vars']. > >datas act vars. > >ren var var1=variable. > >sav out 'varlabs.sav' > >/kee variable to WriteFormat. > >str s1(a256). > >str s2 (a256). > >comp s1=con("ren var ",rtr(variable),"= v",ltr(str(position,f4)),"."). > >comp s2=con("var lab v",ltr(str(position,f4)),'"',rtr(variable),' % > ',rtr(label),'".'). > >wri out '$rennum.sps'/s1. > >wri out '$rennum.sps'/s2. > >exe. > >datas clo vars. > >datas act !dat. > >ins fil='$rennum.sps'. > >*era fil='$rennum.sps'. > >!ifend > >!enddefine. > > > > > > > >*macro call. > > > > > > > >!rennum dat=d1. > > > > > >_________________________________________________________________ > >New Windows 7: Find the right PC for you. Learn more. > >http://windows.microsoft.com/shop > > ===================== > 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 New Windows 7: Simplify what you do everyday. Find the right PC for you. |
|
That way -- fewer keystrokes could be used to create the syntax -- the syntax would still be useful when features that are added to SPSS make abbreviations no longer unique -- quality assurance review would be facilitated -- adapting the syntax to similar tasks would be facilitated -- refining the process would be facilitated -- it would make it easier for people who are trying to help. The improvements to the editor have been great. I have suggested some of this for several years based on the way FORTRAN programmers could use PRETTY on their code (syntax) in the 70's. Until these improvements get into SPSS itself perhaps someone could put together some PYTHON to do it. Art Kendall Social Research Consultants On 4/28/2010 10:57 AM, Ruben van den Berg wrote: Dear David,===================== 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
Art Kendall
Social Research Consultants |
|
In reply to this post by Ruben Geert van den Berg
At 07:52 AM 4/27/2010, Ruben van den Berg wrote:
>My macro (below) is not working. It seems that 'insert file' doesn't >function within a macro because the syntax that is printed in the >viewer actually deviates from the contents of the little syntax file >that's inserted No, INSERT and INCLUDE can't be part of a macro. Both statements take effect when the program text is scanned, before the macro definition is completed and stored. The INSERTed/INCLUDEd text, not the INSERT or INCLUDE statements, become part of the defined macro. ===================== 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 |
|
Richard Ristow wrote:
> At 07:52 AM 4/27/2010, Ruben van den Berg wrote: > >> My macro (below) is not working. It seems that 'insert file' doesn't >> function within a macro because the syntax that is printed in the >> viewer actually deviates from the contents of the little syntax file >> that's inserted > > No, INSERT and INCLUDE can't be part of a macro. Really? I DO have some macros that use INCLUDE inside a macro, and they work OK. As a matter of fact, some are very used by people too. See the second macro (MULTIMW) at this link: http://gjyp.nl/marta/KruskalWallisPostHoc.sps This reminds me the scientific study that says that bumblebees can't fly (http://www.theness.com/scientists-report-bumblebees-cant-fly/) Best regards, Marta GG PS: sorry for the bumblebees item, all I can say is "it's friday morning" :) -- For miscellaneous SPSS related statistical stuff, visit: http://gjyp.nl/marta/ ===================== 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 Marta Garcia-Granero
At 02:38 AM 4/30/2010, Marta García-Granero wrote:
Richard Ristow wrote: Marta's right. I remembered the behavior of INCLUDE in a macro exactly backward. As she wrote, an INCLUDE/INSERT within a macro definition is not effective when the definition is encountered, and is effective when the macro is invoked. That answer has been posted before, including (sigh) Date: Wed, 21 Jun 2006 11:54:19 -0400 From: Richard Ristow <[hidden email]> Subject: Re: INCLUDE within DEFINE-!ENDDEFINE? To: [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 |
| Free forum by Nabble | Edit this page |
