Here is my dilemma.
I have data on four scales for 5 cases. Actually, there are 100+ cases measured on 10 scales; but, because of the nature of the data I do not have access to that dataset and been passing code on. The issue can be seen in this reduce dataset: AA BB CC DD 46 41 53 53 68 69 76 80 54 73 60 68 59 42 68 69 30 25 70 55 I want to create a variable (I call pattern) based on the following rules: For each case: Select only those variables over 64. If the case has no variables over 65 record WNL (Within Normal Limits). Rank the selected variables from High to Low recording their order in the pattern variable. For the above dataset: pattern WNL 4321 24 43 3 Just to get the variable numbers that exceed 64 I was able to use: STRING pattern(A4). DO REPEAT scale = AA TO DD /order = 1 TO 4. DO IF (scale > 65). COMPUTE pattern = CONCAT(pattern, STRING(order,N1)). END IF. END REPEAT. I’ve looked at this for a couple of hours and couldn’t see a solution to create an ordered pattern using spss syntax. I’m completely open for suggestions. TIA. Stephen Salbod, Pace University, NYC |
Untested (no SPSS here):
varstocases /make v from AA BB CC DD /index = index. compute pattern = 1. sort cases by index (a) v (d). if(index eq lag(index)) pattern = lag(pattern) + 1. recode pattern (5 thru hi = 999) (else = copy). value labels pattern 999 "WNL". sort cases by v. casestovars /id = v /index = index. Regards, Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
Administrator
|
DATA LIST LIST / AA BB CC DD .
BEGIN DATA 46 41 53 53 68 69 76 80 54 73 60 68 59 42 68 69 30 25 70 55 END DATA. COMPUTE ID=$CASENUM. DATASET NAME raw. DATASET COPY temp. DATASET ACTIVATE temp. VARSTOCASES /MAKE v from AA BB CC DD /INDEX = index. SELECT IF V GE 64. SORT CASES BY ID (A) v(D). DO IF $CASENUM=1 OR LAG(ID) NE ID. COMPUTE pattern=index. ELSE. IF v NE -999 pattern=LAG(pattern)*10+index. END IF. MATCH FILES / FILE * / BY ID / LAST=L. SELECT IF L . MATCH FILES / FILE raw / FILE * / BY ID/KEEP ID AA BB CC DD pattern. FORMATS pattern (F10.0). ALTER TYPE pattern (Amin). RECODE pattern (" " = "WNL"). LIST.
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, I don't fully understand what your code is doing, but removing the asterisks on the SORT CASES gets me what I'm looking for. I definitely need to spend some time reviewing exactly your code implements the algorithm. Again, Thank you. --Steve
-----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Marso Sent: Saturday, February 01, 2014 4:24 PM To: [hidden email] Subject: Re: SPSS sytax problem DATA LIST LIST / AA BB CC DD . BEGIN DATA 46 41 53 53 68 69 76 80 54 73 60 68 59 42 68 69 30 25 70 55 END DATA. COMPUTE ID=$CASENUM. DATASET NAME raw. DATASET COPY temp. DATASET ACTIVATE temp. VARSTOCASES /MAKE v from AA BB CC DD /INDEX = index. SELECT IF V GE 64. SORT CASES BY *ID (A) *v(D). DO IF $CASENUM=1 OR LAG(ID) NE ID. COMPUTE pattern=index. ELSE. IF v NE -999 pattern=LAG(pattern)*10+index. END IF. MATCH FILES / FILE * / BY ID / LAST=L. SELECT IF L . MATCH FILES / FILE raw / FILE * / BY ID/KEEP ID AA BB CC DD pattern. FORMATS pattern (F10.0). ALTER TYPE pattern (Amin). RECODE pattern (" " = "WNL"). LIST. Albert-Jan Roskam wrote > Untested (no SPSS here): > > varstocases /make v from AA BB CC DD /index = index. > compute pattern = 1. > sort cases by index (a) v (d). > if(index eq lag(index)) pattern = lag(pattern) + 1. > recode pattern (5 thru hi = 999) (else = copy). > value labels pattern 999 "WNL". > sort cases by v. > casestovars /id = v /index = index. > > > Regards, > > Albert-Jan > > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > All right, but apart from the sanitation, the medicine, education, > wine, public order, irrigation, roads, a > > fresh water system, and public health, what have the Romans ever done > for us? > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > >>________________________________ >> From: Salbod < > ssalbod@ > > >>To: > SPSSX-L@.UGA > >>Sent: Saturday, February 1, 2014 6:15 PM >>Subject: [SPSSX-L] SPSS sytax problem >> >> >>Here is my dilemma. >>I have data on four scales for 5 cases. Actually, there are 100+ cases >>measured on 10 scales; but, because of the nature of the data I do not have >>access to that dataset and been passing code on. The issue can be seen >>in this reduce dataset: >> >>AA BB CC DD >>46 41 53 53 >>68 69 76 80 >>54 73 60 68 >>59 42 68 69 >>30 25 70 55 >> >>I want to create a variable (I call pattern) based on the following rules: >> >>For each case: >>Select only those variables over 64. If the case has no variables over >>65 record WNL (Within Normal Limits). >> >>Rank the selected variables from High to Low recording their order in >>the pattern variable. >> >>For the above dataset: >> >>pattern >>WNL >>4321 >>24 >>43 >>3 >> >>Just to get the variable numbers that exceed 64 I was able to use: >> >>STRING pattern(A4). >>DO REPEAT scale = AA TO DD >> /order = 1 TO 4. >>DO IF (scale > 65). >>COMPUTE pattern = CONCAT(pattern, STRING(order,N1)). >>END IF. >>END REPEAT. >> >>I’ve looked at this for a couple of hours and couldn’t see a solution >>to create an ordered pattern using spss syntax. >> >>I’m completely open for suggestions. >> >>TIA. >> >>Stephen Salbod, Pace University, NYC >> >> >> >> >>-- >>View this message in context: >>Sent from the SPSSX Discussion mailing list archive at Nabble.com. >> >>===================== >>To manage your subscription to SPSSX-L, send a message to >> > LISTSERV@.UGA > (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?" -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/SPSS-sytax-problem-tp5724263p5724269.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
|
I bolded the ID (D) piece in Nabble and it looks like it came over as * ID (D) *
Should change IF v NE -999 pattern=LAG(pattern)*10+index. to COMPUTE pattern=LAG(pattern)*10+index. I had previously used a recode but later changed it to SELECT IF.
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 |