Hi Team,
I would like to set cutoff on the basis of number of records in a file. Run syntax only if criteria is met. Let me build you the background : To generate correlation analysis, data for at least 30 respondents must be included in the file. I tried to set the criteria using DO IF statement. But,i am getting the following error message : >Error # 4070. Command name: END IF >The command does not follow an unclosed DO IF command. Maybe the DO IF >command was not recognized because of an error. Use the level-of-control >shown to the left of the SPSS Statistics commands to determine the range of >LOOPs and DO IFs Following the syntax i am using : DEFINE CUTOFF ( ) 30 !ENDDEFINE. GET FILE = 'DataFile'. Define !Group (cuts=!CHAREND ('/') / options = !CMDEND) !DO !vnames !IN (!options) !LET !corr = !quote(!concat(!unquote('Directory\'),'corr','-',!vnames,'.sav')) GET File = 'Directory\Datafile1.sav'. Select If !demogs = !vnames. Execute. Dataset Name Currfile. AGGREGATE /OUTFILE=* /BREAK= /SIZE=N. DO IF SIZE >= Cutoff. Dataset Activate Currfile. CORRELATIONS /VARIABLES= Engagement Drivers /MISSING=PAIRWISE /MATRIX = OUT (!corr). **** HERE I AM GETTING THE ERROR : >Error # 4070. Command name: END IF >The command does not follow an unclosed DO IF command. Maybe the DO IF >command was not recognized because of an error. Use the level-of-control >shown to the left of the SPSS Statistics commands to determine the range of >LOOPs and DO IFs. ****** !DOEND END IF. EXECUTE. !ENDDEFINE. SET MPRINT ON PRINTBACK ON. !Group cuts=Age /options=1 2. It would be very helpful if you suggest any workaround. Thanks in advance ! Ujjawal Bhandari |
Administrator
|
DO IF only allows transformations *not* procedures.
There are work arounds but I'm not going there today!
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?" |
Thanks a ton David for your response. Suggest me work arounds when you think it's the best time ;)
|
Administrator
|
This post was updated on .
Meanwhile review your code. You have !END IF and !IFEND swapped. That however won't have any bearing on the other issue. Maybe reveal your broader plan. Perhaps there are alternative approaches (hint MATRIX or gasp python).
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?" |
This post was updated on .
David, sorry for the late reply. Must apologize for this .
Instead of DO IF i used !IF-!THEN. But, this gives me an error while processing this line !IF SIZE >= Cutoff !THEN ">In an !IF command, the parenthesized logical expression is missing. !IF must >be followed by a parenthesized logical expression and a !THEN command. >This command not executed. I understand variable SIZE must be a macro expression. I had spent almost a day to make this code running but unable to crack it. Any help would be highly appreciated ! David, if you remember my query related to matrix posted last week. This query is linked to that problem. I wish to run the analysis by sub group level. I succeeded using !DO loop. Now, i want to take this to the next level by setting minimum respondent level cutoff. |
Administrator
|
As I hinted previously. MATRIX!
MATRIX. Load data here (say raw data is in X). DO IF (NROW(X) > !cutoff). whatever matrix code to do your calculations. END IF. END MATRIX. It is a RPITA to resolve data values in MACRO. You know I do consulting and training for a living. My tips on SPSSX-L are really just the tip of an iceberg.
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?" |
This post was updated on .
Thank you so much David for taking time out of your schedule.
In this case, matrix calculations are performed on correlation matrix. Hence, NROW doesn't serve the purpose. I mean raw data is in correlation matrix format. I am sorry if i am missing something silly here. Just wanted to let you know that i used AGGREGATE to count the number of cases. Is it the right approach? I am trying to assign the number of records to LET statement and then setting criteria on the basis of it. GET File = 'Datafile.sav'. Select If Var1 = 2. Execute. AGGREGATE /OUTFILE=* /BREAK= /SIZE=N. !LET !a = SIZE !IF (!a !GE 30) !THEN ***Correlation analysis if a criteria is met otherwise STOP****** Now, the situation is : NO ERROR but syntax is not considering the number of respondent criteria. |
Administrator
|
"!LET !a = SIZE "
And you found to your dismay that MACRO is clueless WRT SIZE! What I was hinting at was to use MATRIX to compute the correlation matrix and do the bookkeeping . IIRC when you were reading stacked correlation matrices you were getting silliness for the element names. (of course there is no way to know how many there are or any sane way to address them within MATRIX so it is rather useless for raw split file matrix input -unless I am missing something-). Still, at this point you need to lay out the big picture you are trying to paint.
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?" |
Thanks David...Tough time has come . I need to have patience ;)
|
Administrator
|
Patience is a good thing. A plan is better.
Take a few steps back and lay out exactly what needs to be done. Solve each step one at a time. --
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?" |
I will be out of the office until March 20th with limited access to e-mail.
===================== 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 David Marso
As you suggested, i took a few steps back. Thought of all the possibilities that i could.
One of these is as follows : To workaround this problem, i tried to convert values of all the variables to system missing.This serves the purpose. However, it gives errors while executing regression and matrix statements as no values in both independent and dependent variables. AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK= /SIZE=N. DO IF (SIZE LT 30). RECODE Drivers (ELSE = SYSMIS). CORRELATIONS /VARIABLES= Engagement Drivers /MISSING=PAIRWISE /MATRIX = OUT ('Directory\corr.sav'). oms /select tables /if commands =['Regression'] SUBTYPES=['Coefficients'] /destination format =SAV outfile ='Directory\Beta.sav' /columns sequence =[RALL CALL LALL]. regression /dependent Engagement /method= enter Drivers. omsend. ***THEN ALL THE MATRIX STUFF***** This is the only thing that is spoiling my whole program. |
Administrator
|
Back up even further.
I don't want to know what you are doing. Because that is obviously problematic. I want you to lay out what you are 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?" |
Administrator
|
Consider the original dilemma: MATRIX was interpreting the SPSS matrix file and parsing out sets of materials which would be very difficult to resolve (even I would abandon all hope...-the code would be too ugly and I don't have enough bleach on hand-). Consider wiping those assumptions and passing a 'sanitized' version (ie NIX all of the indicators of it being a matrix file from CORR (see AUTORECODE and DELETE VARIABLES)). Of course you will need to enumerate and process the sub matrices on your own.
That is all I have to say on this.
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?" |
Administrator
|
OK One more: But thats all folks.
-- GET FILE='C:\Program Files\SPSS\Employee data.sav'. SORT CASES BY JOBCAT. SPLIT FILE BY JOBCAT. DATASET DECLARE corrout. CORRELATIONS /MATRIX OUT (corrout) /VARIABLES=salary salbegin jobtime prevexp /PRINT=TWOTAIL NOSIG /MISSING=PAIRWISE. DATASET ACTIVATE corrout. SPLIT FILE OFF. AUTORECODE ROWTYPE_ /INTO RT. DELETE VARIABLES ROWTYPE_ VARNAME_ . LIST. MATRIX. GET DATA / FILE * / VAR ALL. PRINT DATA / FORMAT "F8.3". END MATRIX. Run MATRIX procedure: DATA 1.000 27838.54 14096.05 81.066 85.039 2.000 1.000 7567.995 2907.474 10.110 95.275 4.000 1.000 363.000 363.000 363.000 363.000 3.000 1.000 363.000 363.000 363.000 363.000 3.000 1.000 363.000 363.000 363.000 363.000 3.000 1.000 363.000 363.000 363.000 363.000 3.000 1.000 1.000 .683 .147 -.214 1.000 1.000 .683 1.000 -.053 .080 1.000 1.000 .147 -.053 1.000 -.024 1.000 1.000 -.214 .080 -.024 1.000 1.000 2.000 30938.89 15077.78 81.556 298.111 2.000 2.000 2114.616 1341.235 8.487 101.426 4.000 2.000 27.000 27.000 27.000 27.000 3.000 2.000 27.000 27.000 27.000 27.000 3.000 2.000 27.000 27.000 27.000 27.000 3.000 2.000 27.000 27.000 27.000 27.000 3.000 2.000 1.000 .077 -.096 .284 1.000 2.000 .077 1.000 -.543 -.028 1.000 2.000 -.096 -.543 1.000 .076 1.000 2.000 .284 -.028 .076 1.000 1.000 3.000 63977.80 30257.86 81.155 77.619 2.000 3.000 18244.78 9980.979 10.410 73.260 4.000 3.000 84.000 84.000 84.000 84.000 3.000 3.000 84.000 84.000 84.000 84.000 3.000 3.000 84.000 84.000 84.000 84.000 3.000 3.000 84.000 84.000 84.000 84.000 3.000 3.000 1.000 .693 .168 .094 1.000 3.000 .693 1.000 -.010 .479 1.000 3.000 .168 -.010 1.000 .091 1.000 3.000 .094 .479 .091 1.000 1.000 ------ END MATRIX ----- Compared to presanitized matrix file: jobcat ROWTYPE_ VARNAME_ salary salbegin jobtime prevexp 1 MEAN 27838.5399 14096.0468 81.0661157 85.0385675 1 STDDEV 7567.99496 2907.47415 10.1104963 95.2746460 1 N salary 363.000000 363.000000 363.000000 363.000000 1 N salbegin 363.000000 363.000000 363.000000 363.000000 1 N jobtime 363.000000 363.000000 363.000000 363.000000 1 N prevexp 363.000000 363.000000 363.000000 363.000000 1 CORR salary 1.0000000 .6826561 .1466784 -.2140851 1 CORR salbegin .6826561 1.0000000 -.0531836 .0799518 1 CORR jobtime .1466784 -.0531836 1.0000000 -.0244330 1 CORR prevexp -.2140851 .0799518 -.0244330 1.0000000 2 MEAN 30938.8889 15077.7778 81.5555556 298.111111 2 STDDEV 2114.61641 1341.23460 8.4867922 101.426492 2 N salary 27.0000000 27.0000000 27.0000000 27.0000000 2 N salbegin 27.0000000 27.0000000 27.0000000 27.0000000 2 N jobtime 27.0000000 27.0000000 27.0000000 27.0000000 2 N prevexp 27.0000000 27.0000000 27.0000000 27.0000000 2 CORR salary 1.0000000 .0770036 -.0960843 .2835744 2 CORR salbegin .0770036 1.0000000 -.5427114 -.0279289 2 CORR jobtime -.0960843 -.5427114 1.0000000 .0759741 2 CORR prevexp .2835744 -.0279289 .0759741 1.0000000 3 MEAN 63977.7976 30257.8571 81.1547619 77.6190476 3 STDDEV 18244.7760 9980.97939 10.4102522 73.2598782 3 N salary 84.0000000 84.0000000 84.0000000 84.0000000 3 N salbegin 84.0000000 84.0000000 84.0000000 84.0000000 3 N jobtime 84.0000000 84.0000000 84.0000000 84.0000000 3 N prevexp 84.0000000 84.0000000 84.0000000 84.0000000 3 CORR salary 1.0000000 .6926902 .1675453 .0938535 3 CORR salbegin .6926902 1.0000000 -.0100060 .4788105 3 CORR jobtime .1675453 -.0100060 1.0000000 .0910731 3 CORR prevexp .0938535 .4788105 .0910731 1.0000000 Number of cases read: 30 Number of cases listed: 30
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?" |
This post was updated on .
Thanks a ton David :) I won't bother you more.
Status : I found a quick fix. When criteria is not met, i let SPSS to run all the analysis and then match the final file with the file wherein variable for respondent size. And then convert all the variables to sysmis using DO IF and Recode. The problem with the matrix approach is processing the sub matrices when number of records are less than 30. Because you had made them blank SPSS gives errors while processing the statements. I wish a command like DO IF for procedures :( |
Administrator
|
Like I said: Study MATRIX and roll your own when necessary.
MATRIX supports a DO IF -END IF and you can smash any MATRIX code in between so you DO HAVE A CONDITIONAL PROCEDURE. You just have to roll it yourself . I thought that was what your original issue was in the first place (you had someone else's MATRIX program and were trying to hammer away with SPLIT FILE and it bit you). TIP: You might want to venture beyond your little thread here and review what other topics have been posted today ;-) You perhaps will find a pleasant surprise !!!!!!!
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 Ujjawal
There is a command like DO IF for procedures. Read up on the FILTER command.
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Ujjawal Sent: Monday, March 18, 2013 1:39 PM To: [hidden email] Subject: Re: DO IF Error Thanks a ton David :) I won't bother you more. Status : I found a quick fix. When criteria is not met, i let SPSS to run all the analysis and then match the final file with the file wherein variable for respondent size. And then convert all the variables to sysmis. The problem with the matrix approach is processing the sub matrices when number of records are less than 30. Because you had made them blank SPSS gives errors while processing the statements. I wish a command like DO IF for procedures :( -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/DO-IF-Error-tp5718730p5718827. 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 |
In reply to this post by Ujjawal
> And then convert all the variables to sysmis.
If you, the user, are doing the transformation then they should be assigned a USER-MISSING value. In the long run, it is very important for quality assurance and debugging to maintain the distinction between "missing for a known reason" and "missing because the system was not able to obey your instructions". It is usually bad practice to put sysmis on the right side of an assignment command. The exception would be sometimes in a recode where sysmis in the input variable is wanted as sysmis on the new variable. I wonder if there could be a Python app that looked for bad habits like that. Perhaps this list could make a list of things that gave a "are you sure you want to". Art Kendall Social Research Consultants On 3/18/2013 3:38 PM, Ujjawal wrote: > Thanks a ton David :) I won't bother you more. > > Status : I found a quick fix. When criteria is not met, i let SPSS to run > all the analysis and then match the final file with the file wherein > variable for respondent size. And then convert all the variables to sysmis. > > The problem with the matrix approach is processing the sub matrices when > number of records are less than 30. Because you had made them blank SPSS > gives errors while processing the statements. > > I wish a command like DO IF for procedures :( > > > > -- > View this message in context: http://spssx-discussion.1045642.n5.nabble.com/DO-IF-Error-tp5718730p5718827.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
Art Kendall
Social Research Consultants |
@ Art Kendall: I second that. But the problem is i am unable to find a way to get it run without converting all the variables to symsis. If the number of records in a raw data file is less than 30 this conversion will happen otherwise missing for a known reason.
As David suggested, i have started studying MATRIX-END MATRIX. I hope i will be able to crack it using MATRIX. |
Free forum by Nabble | Edit this page |