|
Hi listers,
I am doing a loop with a vector, but I am having a problem a little problem. I want to change the value 5 to missing... I checked some codes, pasting the code and they used the SYSMIS. But I got an error... So, what should I use to inform that a value is missing at the code! vector vector=v1 to v53/nouv(53,f8.0). loop #var=1 to 53. do if vector(#var)=0. compute nouv(#var)=0. else if vector(#var)=5. compute nouv(#var)=sysmis. else. compute nouv(#var)=1. end if. end loop. exe. Thanks in advance, Ribeiro ===================== 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 |
|
Hi, try to use $sysmis instead.
compute nouv(#var) = $sysmis. Have a nice weekend, Jan -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ribeiro Sent: Friday, October 26, 2007 4:42 AM To: [hidden email] Subject: Code: Value to Missing Hi listers, I am doing a loop with a vector, but I am having a problem a little problem. I want to change the value 5 to missing... I checked some codes, pasting the code and they used the SYSMIS. But I got an error... So, what should I use to inform that a value is missing at the code! vector vector=v1 to v53/nouv(53,f8.0). loop #var=1 to 53. do if vector(#var)=0. compute nouv(#var)=0. else if vector(#var)=5. compute nouv(#var)=sysmis. else. compute nouv(#var)=1. end if. end loop. exe. Thanks in advance, Ribeiro ===================== 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 _____ Tato zpráva a všechny připojené soubory jsou důvěrné a určené výlučně adresátovi(-ům). Jestliže nejste oprávněným adresátem, je zakázáno jakékoliv zveřejňování, zprostředkování nebo jiné použití těchto informací. Jestliže jste tento mail dostali neoprávněně, prosím, uvědomte odesilatele a smažte zprávu i přiložené soubory. Odesilatel nezodpovídá za jakékoliv chyby nebo opomenutí způsobené tímto přenosem. This message and any attached files are confidential and intended solely for the addressee(s). Any publication, transmission or other use of the information by a person or entity other than the intended addressee is prohibited. If you receive this in error please contact the sender and delete the message as well as all attached documents. The sender does not accept liability for any errors or omissions as a result of the transmission. -.- -- ===================== 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 |
|
Dear listers,
In one (probably, old) SPSS syntax file I have encountered the command "run name". It has syntax like: ----------------------- Run name some words. ----------------------- It's only effect seems to be the insertion of page title in the output of kind "some words". I have not find this command in the syntax reference for SPSS 15. I guess, it is one of the obsolete commands. Could some one comment this? Does it have some options/subcommands? Best, Anton ===================== 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 |
|
Old commands never die; they just become aliases for new commands. It appears to be functionally equivalent to TITLE.
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Anton Balabanov Sent: Friday, October 26, 2007 10:40 AM To: [hidden email] Subject: Run name Dear listers, In one (probably, old) SPSS syntax file I have encountered the command "run name". It has syntax like: ----------------------- Run name some words. ----------------------- It's only effect seems to be the insertion of page title in the output of kind "some words". I have not find this command in the syntax reference for SPSS 15. I guess, it is one of the obsolete commands. Could some one comment this? Does it have some options/subcommands? Best, Anton ===================== 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 |
|
In reply to this post by Ribeiro-2
At 10:42 PM 10/25/2007, Ribeiro wrote:
>>What should I use to inform that a value is missing at the code! >> >>compute nouv(#var)=sysmis. As Jan Spousta wrote, it's >compute nouv(#var) = $sysmis. Now, you have (with that correction, some reformatting, and drop the EXECUTE), >vector vector=v1 to v53/nouv(53,f8.0). >loop #var=1 to 53. >. do if vector(#var)=0. >. compute nouv(#var)=0. >. else if vector(#var)=5. >. compute nouv(#var)=sysmis. >. else. >. compute nouv(#var)=1. >. end if. >end loop. Alternatively, try this: RECODE v1 to v53 (0 = 0) (5 = SYSMIS) (ELSE = 1) INTO nouv1 TO nouv53. FORMATS nouv1 TO nouv53 (F8.0). (Use "sysmis", not "$sysmis", in RECODE.) Here's a demo, with 5 elements instead of 53. This is SPSS 14 draft output (WRR:not saved separately): |-----------------------------|---------------------------| |Output Created |26-OCT-2007 16:07:17 | |-----------------------------|---------------------------| CaseID v1 v2 v3 v4 v5 001 2 1 4 1 1 002 5 4 4 3 1 003 1 2 0 5 3 004 0 2 5 0 5 005 2 1 0 4 2 006 5 3 1 1 4 Number of cases read: 6 Number of cases listed: 6 RECODE v1 to v5 (0 = 0) (5 = SYSMIS) (ELSE = 1) INTO nouv1 TO nouv5. FORMATS nouv1 TO nouv5 (F8.0). LIST. List |-----------------------------|---------------------------| |Output Created |26-OCT-2007 16:08:55 | |-----------------------------|---------------------------| CaseID v1 v2 v3 v4 v5 nouv1 nouv2 nouv3 nouv4 nouv5 001 2 1 4 1 1 1 1 1 1 1 002 5 4 4 3 1 . 1 1 1 1 003 1 2 0 5 3 1 1 0 . 1 004 0 2 5 0 5 0 1 . 0 . 005 2 1 0 4 2 1 1 0 1 1 006 5 3 1 1 4 . 1 1 1 1 Number of cases read: 6 Number of cases listed: 6 =================== APPENDIX: Test data =================== * ................................................................. . * ................. Test data ..................... . SET RNG = MT /* 'Mersenne twister' random number generator */ . SET MTINDEX = 3004 /* Providence, RI telephone book */ . INPUT PROGRAM. . NUMERIC CaseID (N3). . LEAVE CaseID. . NUMERIC v1 TO v5 (F2). . LOOP CaseID = 1 TO 6. . VECTOR v = v1 TO v5. . LOOP #IX = 1 TO 5. . COMPUTE v(#IX) = TRUNC(RV.UNIFORM(0,6)). . END LOOP. . END CASE. . END LOOP. END FILE. END INPUT PROGRAM. LIST. ===================== 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 |
|
Hey folks,
I know that I've read many posts where quite a few of the posters have mentioned that we should try to stay away from the EXECUTE command, especially when working with large datasets. However, are there any rules about when the EXECUTE command SHOULD be used for appropriate command executions. My query stems from a personal experience with my data. I had a bit of code that looked a bit like: *********************************************** MISSING VALUE var1 (). /* cmd1: cleared missing values */ . DO IF var2=1. /* cmd2: some DO IF commands */ DO IF var1=7. COMPUTE var3=2. ELSE IF var1=8. COMPUTE var3=3. END IF. END IF. . MISSING VALUE var1 (7, 8, 9). /* cmd3: reassign missing values */ . *********************************************** If I run the code in three parts (i.e. highlight and run cmd1, then highlight and run cmd2, then highlight and run cmd3) the values assigned to var3 are perfect. If I highlight the whole code and run it in one go, then the ELSE IF statement (and the accompanying COMPUTE command) don't seem to be doing anything. However, If I place an EXECUTE command after the second "END IF." statement, and run the whole code, it all works just fine. Therefore, are EXECUTE commands required after "DO IF"s?? Or is the whole, MISSING VALUE statement throwing something off?? Thanks a heap in advance. - Shahrukh ===================== 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 |
|
Thanks Simon. It's good to have this list handy!! :)
- Shahrukh > -----Original Message----- > From: Simon Freidin [mailto:[hidden email]] > Sent: Friday, October 26, 2007 5:58 PM > To: Hashmi, Syed S > Subject: Re: Use of EXECUTE > > http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0607&L=spssx-l&P=R9514&D=0 > > On 27/10/2007, at 8:47 AM, Hashmi, Syed S wrote: > > > Hey folks, > > > > I know that I've read many posts where quite a few of the posters have > > mentioned that we should try to stay away from the EXECUTE command, > > especially when working with large datasets. However, are there any > > rules about when the EXECUTE command SHOULD be used for appropriate > > command executions. > > > > My query stems from a personal experience with my data. I had a > > bit of > > code that looked a bit like: > > > > > > *********************************************** > > MISSING VALUE var1 (). /* cmd1: cleared missing values */ > > . > > DO IF var2=1. /* cmd2: some DO IF commands */ > > DO IF var1=7. > > COMPUTE var3=2. > > ELSE IF var1=8. > > COMPUTE var3=3. > > END IF. > > END IF. > > . > > MISSING VALUE var1 (7, 8, 9). /* cmd3: reassign missing values */ > > . > > *********************************************** > > > > > > If I run the code in three parts (i.e. highlight and run cmd1, then > > highlight and run cmd2, then highlight and run cmd3) the values > > assigned > > to var3 are perfect. If I highlight the whole code and run it in > > go, then the ELSE IF statement (and the accompanying COMPUTE command) > > don't seem to be doing anything. > > > > However, If I place an EXECUTE command after the second "END IF." > > statement, and run the whole code, it all works just fine. > > > > Therefore, are EXECUTE commands required after "DO IF"s?? Or is the > > whole, MISSING VALUE statement throwing something off?? > > > > Thanks a heap in advance. > > > > - Shahrukh > > > > ===================== > > 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 |
|
In reply to this post by Hashmi, Syed S
At 06:47 PM 10/26/2007, Hashmi, Syed S wrote:
>I know that I've read many posts where quite a >few of the posters have mentioned that we should >try to stay away from the EXECUTE command, Guilty as charged. Major repeat offender. Unrepentant. >However, are there any rules about when the >EXECUTE command SHOULD be used for appropriate command executions. For a summary, in *SPSS Programming and Data Management, 4th Edition*(1), see subsection "Part I: Data Management >> 2. Best Practices and Efficiency Tips >> Use EXECUTE Sparingly", p. 12ff. >I had a bit of code that looked a bit like: > > >*********************************************** >MISSING VALUE var1 (). /* cmd1: cleared missing values */ >. >DO IF var2=1. /* cmd2: some DO IF commands */ > DO IF var1=7. > COMPUTE var3=2. > ELSE IF var1=8. > COMPUTE var3=3. > END IF. >END IF. >. >MISSING VALUE var1 (7, 8, 9). /* cmd3: reassign missing values */ >. >*********************************************** > >If I run the code in three parts (i.e. highlight >and run cmd1, then highlight and run cmd2, then >highlight and run cmd3) the values assigned to >var3 are perfect. If I highlight the whole code >and run it in one go, then the ELSE IF statement >(and the accompanying COMPUTE command) don't >seem to be doing anything. However, If I place >an EXECUTE command after the second "END IF." >statement, and run the whole code, it all works just fine. > >Therefore, are EXECUTE commands required after >"DO IF"s?? Or is the whole, MISSING VALUE >statement throwing something off?? It's the latter. *One* MISSING VALUE statement is in effect for the transformation program: the last one encountered. So . MISSING VALUE var1 (7, 8, 9). /* cmd3: reassign missing values */ is in effect for the whole of yours. If you put an EXECUTE before that statement, then it's in a different transformation program, and the first MISSING VALUES statement is in effect. You write, "the ELSE IF statement (and the accompanying COMPUTE command) don't seem to be doing anything." In fact, neither COMPUTE should ever be executed. In . DO IF var1=7. . COMPUTE var3=2. . ELSE IF var1=8. . COMPUTE var3=3. . END IF. If "var1" is 7, that tests as 'missing', not the number 7; the DO IF tests 'missing'. The COMPUTE statement governed by the DO IF is not executed, *nor are any of the other tests and clauses in the DO IF construct*. Now, what I'd do for yours is nullify user-missing values in specific tests, using the VALUE function: . DO IF VALUE(var1)=7. . COMPUTE var3=2. . ELSE IF VALUE(var1)=8. . COMPUTE var3=3. . END IF. This is one of the documented legitimate uses of EXECUTE: to run with a MISSING VALUES specification other than the one you want to leave in effect at the end. However, this use can usually be worked around by use of VALUE(), etc. That can be a good idea; as always, EXECUTE forces a full pass through the data and can slow processing for large files -- as people like me keep saying. -Good luck! Richard ................................... (1) Levesque, Raynald and SPSS Inc., *SPSS Programming and Data Management, 4th Edition: A Guide for SPSS and SAS® Users*. SPSS, Inc., Chicago, 2007. It may be downloaded free as a PDF file: http://www.spss.com/spss/SPSSdatamgmt_4e.pdf (4th edition). ===================== 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 |
|
Thanks Richard,
I'm not surprised you replied to my post since... as you mentioned... I got most of my "stay away from EXECUTE" lessons from you! :) I got an earlier reply from Simon, who had linked up to one of his earlier posts that had a list on when to use EXECUTE. The reply was sent just to me, so I had replied to him and CCed it to the list (for others who might need that list too). Incidentally, you wrote that neither of the DO IF commands should have worked... you're right, neither one did. My actual code had an additional two lines of DO IF statements that weren't based on any of the "MISSING" values, and they had worked, but yes, the others didn't. Finally, thanks for the VALUE function. That would make things a lot simpler. - Shahrukh > -----Original Message----- > From: Richard Ristow [mailto:[hidden email]] > Sent: Friday, October 26, 2007 8:22 PM > To: Hashmi, Syed S; [hidden email] > Subject: Re: Use of EXECUTE > > At 06:47 PM 10/26/2007, Hashmi, Syed S wrote: > > >I know that I've read many posts where quite a > >few of the posters have mentioned that we should > >try to stay away from the EXECUTE command, > > Guilty as charged. Major repeat offender. Unrepentant. > > >However, are there any rules about when the > >EXECUTE command SHOULD be used for appropriate command executions. > > For a summary, in *SPSS Programming and Data > Management, 4th Edition*(1), see subsection "Part > I: Data Management >> 2. Best Practices and > Efficiency Tips >> Use EXECUTE Sparingly", p. 12ff. > > >I had a bit of code that looked a bit like: > > > > > >*********************************************** > >MISSING VALUE var1 (). /* cmd1: cleared missing values */ > >. > >DO IF var2=1. /* cmd2: some DO IF commands */ > > DO IF var1=7. > > COMPUTE var3=2. > > ELSE IF var1=8. > > COMPUTE var3=3. > > END IF. > >END IF. > >. > >MISSING VALUE var1 (7, 8, 9). /* cmd3: reassign missing values */ > >. > >*********************************************** > > > >If I run the code in three parts (i.e. highlight > >and run cmd1, then highlight and run cmd2, then > >highlight and run cmd3) the values assigned to > >var3 are perfect. If I highlight the whole code > >and run it in one go, then the ELSE IF statement > >(and the accompanying COMPUTE command) don't > >seem to be doing anything. However, If I place > >an EXECUTE command after the second "END IF." > >statement, and run the whole code, it all works just fine. > > > >Therefore, are EXECUTE commands required after > >"DO IF"s?? Or is the whole, MISSING VALUE > >statement throwing something off?? > > It's the latter. > > *One* MISSING VALUE statement is in effect for > the transformation program: the last one encountered. So > > . MISSING VALUE var1 (7, 8, 9). /* cmd3: reassign missing values */ > > is in effect for the whole of yours. If you put > an EXECUTE before that statement, then it's in a > different transformation program, and the first > MISSING VALUES statement is in effect. > > You write, "the ELSE IF statement (and the > accompanying COMPUTE command) don't seem to be > doing anything." In fact, neither COMPUTE should ever be executed. In > > . DO IF var1=7. > . COMPUTE var3=2. > . ELSE IF var1=8. > . COMPUTE var3=3. > . END IF. > > If "var1" is 7, that tests as 'missing', not the > number 7; the DO IF tests 'missing'. The COMPUTE > statement governed by the DO IF is not executed, > *nor are any of the other tests and clauses in the DO IF construct*. > > Now, what I'd do for yours is nullify > user-missing values in specific tests, using the VALUE function: > > . DO IF VALUE(var1)=7. > . COMPUTE var3=2. > . ELSE IF VALUE(var1)=8. > . COMPUTE var3=3. > . END IF. > > This is one of the documented legitimate uses of > EXECUTE: to run with a MISSING VALUES > specification other than the one you want to > leave in effect at the end. However, this use can > usually be worked around by use of VALUE(), > etc. That can be a good idea; as always, EXECUTE > forces a full pass through the data and can slow > processing for large files -- as people like me keep saying. > > -Good luck! > Richard > ................................... > (1) Levesque, Raynald and SPSS Inc., *SPSS > Programming and Data Management, 4th Edition: A > Guide for SPSS and SAS(r) Users*. SPSS, Inc., Chicago, 2007. > > It may be downloaded free as a PDF file: > http://www.spss.com/spss/SPSSdatamgmt_4e.pdf (4th edition). ===================== 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 Ribeiro-2
It is better programming practice to reserve *sysmis *for circumstances
where the software cannot assign a value. Since the value is missing because you (the user) assign it to be missing, you should use a user missing value. If I understand what you are trying to do, something like this untested code should do it. recode v1 to v53 (0=0)(5=5)(else=1) into nouv01 to nouv53. formats nouv01 to nouv53(f1). missing values nouv01 to nouv53 (5). Art Kendall Social Research Consultants Ribeiro wrote: > Hi listers, > > I am doing a loop with a vector, but I am having a problem a little > problem. I want to change the value 5 to missing... I checked some codes, > pasting the code and they used the SYSMIS. But I got an error... So, what > should I use to inform that a value is missing at the code! > > vector vector=v1 to v53/nouv(53,f8.0). > loop #var=1 to 53. > do if vector(#var)=0. > compute nouv(#var)=0. > else if vector(#var)=5. > compute nouv(#var)=sysmis. > else. > compute nouv(#var)=1. > end if. > end loop. > exe. > > Thanks in advance, > > Ribeiro > > ===================== > 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 |
|
In reply to this post by Hashmi, Syed S
A re-post, with editing, of a list I made a while ago:
Date: Thu, 04 May 2006 12:10:14 -0400 To: SPSS discussion list <[hidden email]> From: Richard Ristow <[hidden email]> Subject: EXECUTE is sometimes useful Generally, don't use EXECUTE. Why use it, ever? Again, see section "Use EXECUTE Sparingly" in Levesque, Raynald and SPSS Inc., *SPSS Programming and Data Management, 4th Edition: AGuide for SPSS and SAS® Users*. SPSS, Inc., Chicago, 2007. It may be downloaded free as a PDF file: http://www.spss.com/spss/SPSSdatamgmt_4e.pdf (That section is also in earlier editions, if you have one of those.) To summarize, use EXECUTE when, -> The purpose of your transformation program is to write data as it runs (using XSAVE, WRITE, or PRINT), and no procedure will be run to use the working file afterward. (See my posting "Re: How to count occurrence of combo?", Mon, 1 May 2006 17:09:54 -0400) -> You're doing selections that depend on multiple cases: for example, "keep the cases *after* ones where Y=1"; "keep every fifth case". Then, you often have to calculate a KEEP_IT variable to mark which cases are to be kept; issue EXECUTE; and SELECT IF (KEEP_IT=1). (See "Using $CASENUM to Select Cases" in Raynald's book, and See http://www.spsstools.net/spsstips.htm on his Web site.) -> Your logic requires using two different sets of MISSING VALUES for one variable. Only one set of MISSING VALUES can be in effect during one data pass. (See "MISSING VALUES Command".) However, such logic can usually be avoided with careful coding, including using functions MISSING and VALUE to explicitly test values flagged as 'missing'. -> LAG: You want to take the LAG of a variable, transform the same variable, but have the LAG 'see' the pre-transformed value (see "Lag Functions"). (I'd suggest, though, not transforming any variable that you are also LAGging. There are generally other ways to the same result.) Finally, -> You're working interactively, and want to see the results of transformations in the Data Editor. (Menu Transform/Run Pending Transformations issues an EXECUTE.) If you were going to run a procedure anyway, this slows things down; but if you want to see the results first, well, we have computers to produce the results when we need them. HOWEVER, this may have given people the idea that an EXECUTE is necessary after a transformation command, to make the transformation take effect. No, it isn't; the transformation will take place as soon as its result is needed. ===================== 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 |
