Fw: Help with selecting records - reply to David Marso

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Fw: Help with selecting records - reply to David Marso

thara vardhan-2
Hi David

Thank you so much - the syntax you have sent works perfectly.
Yes you are absolutely right about CASESTOVARS. I could not use it b'coz i had too many variables and records.
Interestingly I have to use the same logic for selecting records from another file too. However that file has 3 descriptive variables that are not recorded in any systematic order.  

Example: All records are domestic or personal violence related.  
Assoc1                                                                                     Assoc2         Assoc3  
MENTAL ILLNESS RELATED        DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED
MENTAL ILLNESS RELATED        ALCOHOL RELATED                  DOMESTIC VIOLENCE RELATED DRUG RELATED                  DOMESTIC VIOLENCE RELATED
DOMESTIC VIOLENCE RELATED     SEXUAL ABUSE RELATED          ALCOHOL RELATED
DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED               MENTAL ILLNESS RELATED ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     DRUG RELATED
ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     MENTAL ILLNESS RELATED
DRUG RELATED                     DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED DRUG RELATED                  MENTAL ILLNESS RELATED        DOMESTIC VIOLENCE RELATED
DRUG RELATED                  ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED
MENTAL ILLNESS RELATED        DRUG RELATED                  DOMESTIC VIOLENCE RELATED PERSONAL VIOLENCE RELATED     ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED
TRANSIT RELATED               ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED
TRANSIT RELATED               DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED


From the above i have to count

Alcohol, Drugs and Mental Illness
Alcohol and Drugs Related
Alcohol and Mental Illness Related
Alcohol Related
Drug Related
Mental Illness Related
Mental Illness and Drug Related
No Associated Factor

Can you help me please?

thanks
regards
thara
















_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

The information contained in this email is intended for the named recipient(s)
only. It may contain private, confidential, copyright or legally privileged
information. If you are not the intended recipient or you have received this
email by mistake, please reply to the author and delete this email immediately.
You must not copy, print, forward or distribute this email, nor place reliance
on its contents. This email and any attachment have been virus scanned. However,
you are requested to conduct a virus scan as well. No liability is accepted
for any loss or damage resulting from a computer virus, or resulting from a delay
or defect in transmission of this email or any attached file. This email does not
constitute a representation by the NSW Police Force unless the author is legally
entitled to do so.


Reply | Threaded
Open this post in threaded view
|

Re: Fw: Help with selecting records - reply to David Marso

David Marso
Administrator
Hi Thara,
  I hope the following makes some sense.
 The previous syntax of course cannot directly apply as it is designed only for binary situations.  This one can be readily generalized to almost any situation similar to yours.
Please study this and do the RTFM thing if any of it is not familiar.  Very powerful technique.
I call it the Slice and Dice/Splatter/Mop Up method SADAMU for short (I just made that up).
HTH, David
---
DATA LIST LIST (",")  /ID (F2) A1 (A255) A2 (A255) A3 (A255) .
BEGIN DATA
1, ,MENTAL ILLNESS RELATED        DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED ,
2, MENTAL ILLNESS RELATED        ALCOHOL RELATED                  DOMESTIC VIOLENCE RELATED , ,DRUG RELATED                  DOMESTIC VIOLENCE RELATED
3, ,DOMESTIC VIOLENCE RELATED     SEXUAL ABUSE RELATED          ALCOHOL RELATED
4,DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED               MENTAL ILLNESS RELATED , ,ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     DRUG RELATED
5, ,ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     MENTAL ILLNESS RELATED ,
6,DRUG RELATED                     DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED , ,DRUG RELATED                  MENTAL ILLNESS RELATED        DOMESTIC VIOLENCE RELATED
7, ,DRUG RELATED                  ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED ,
8,MENTAL ILLNESS RELATED        DRUG RELATED                  DOMESTIC VIOLENCE RELATED , ,PERSONAL VIOLENCE RELATED     ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED
9, ,TRANSIT RELATED               ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED .
10,TRANSIT RELATED               DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED , ,
END DATA.
LIST.
* PARSE the individual fields into parts /General parser for strings*.
DO REPEAT V=A1 TO A3 /VEC=V_A1_ V_A2_ V_A3_ .
+  COMPUTE V=LTRIM(V).
+  VECTOR VEC(3,A30).
+  COMPUTE #I=1.
+  LOOP.
+    COMPUTE #=INDEX(V,"RELATED").
+    DO IF # GT 0.
+      COMPUTE VEC(#I)=SUBSTR(V,1,#-1).
+      COMPUTE V=LTRIM(SUBSTR(V,#+7)).
+      COMPUTE #I=#I+1.
+    END IF.
+  END LOOP IF # EQ 0.
END REPEAT.
********.
* GO WIDE to LONG /OLD SKOOL BV2C logic *.
VECTOR V=V_A1_1 TO V_A3_3.
STRING CLASS(A30).
LOOP Source=1 TO 3.
+  LOOP INDEX=1 TO 3.
+    COMPUTE CLASS=LTRIM(RTRIM( V((Source-1)*3+INDEX))).
+    DO IF LTRIM(CLASS) NE " ".
+      XSAVE OUTFILE "C:\LONG.SAV" / KEEP ID SOURCE INDEX CLASS.
+    END IF.
+  END LOOP.
END LOOP.
EXECUTE.
****.
* OBTAIN CANONICAL ORDERINGS and concatenate *.
GET FILE "C:\LONG.SAV" .
SORT CASES BY ID SOURCE CLASS.
STRING COMBOS (A12).
IF $CASENUM  EQ 1 OR ( ID NE LAG(ID) OR SOURCE NE LAG(SOURCE)) COMBOS=SUBSTR(CLASS,1,2).
IF ID=LAG(ID) AND SOURCE=LAG(SOURCE) COMBOS=CONCAT(RTRIM(LAG(COMBOS)),"|",SUBSTR(CLASS,1,2)).

* SNAG the final canonical combo and drop the dust *.
MATCH FILES / FILE * /BY ID SOURCE/ LAST=FLAGGED / KEEP ID SOURCE COMBOS .
SELECT IF FLAGGED.
LIST.

ID   SOURCE COMBOS       FLAGGED

 1     2.00 AL|DO|ME        1
 2     1.00 AL|DO|ME        1
 2     3.00 DO|DR           1
 3     2.00 AL|DO|SE        1
 4     1.00 AL|DO|ME        1
 4     3.00 AL|DO|DR        1
 5     2.00 AL|DO|ME        1
 6     1.00 AL|DO|DR        1
 6     3.00 DO|DR|ME        1
 7     2.00 AL|DO|DR        1
 8     1.00 DO|DR|ME        1
 8     3.00 AL|DO|PE        1
 9     2.00 AL|DO|TR        1
10     1.00 AL|DO|TR        1


Number of cases read:  14    Number of cases listed:  14
 
Thara Vardhan wrote
Hi David

Thank you so much - the syntax you have sent works perfectly.
Yes you are absolutely right about CASESTOVARS. I could not use it b'coz i
had too many variables and records.
Interestingly I have to use the same logic for selecting records from
another file too. However that file has 3 descriptive variables that are
not recorded in any systematic order.
Example: All records are domestic or personal violence related.

Assoc1
Assoc2
Assoc3

MENTAL ILLNESS RELATED        DOMESTIC VIOLENCE RELATED     ALCOHOL
RELATED

MENTAL ILLNESS RELATED        ALCOHOL RELATED                  DOMESTIC
VIOLENCE RELATED

DRUG RELATED                  DOMESTIC VIOLENCE RELATED

DOMESTIC VIOLENCE RELATED     SEXUAL ABUSE RELATED          ALCOHOL
RELATED

DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED               MENTAL ILLNESS
RELATED

ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     DRUG RELATED

ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     MENTAL ILLNESS
RELATED

DRUG RELATED                     DOMESTIC VIOLENCE RELATED     ALCOHOL
RELATED

DRUG RELATED                  MENTAL ILLNESS RELATED        DOMESTIC
VIOLENCE RELATED

DRUG RELATED                  ALCOHOL RELATED               DOMESTIC
VIOLENCE RELATED

MENTAL ILLNESS RELATED        DRUG RELATED                  DOMESTIC
VIOLENCE RELATED

PERSONAL VIOLENCE RELATED     ALCOHOL RELATED               DOMESTIC
VIOLENCE RELATED

TRANSIT RELATED               ALCOHOL RELATED               DOMESTIC
VIOLENCE RELATED

TRANSIT RELATED               DOMESTIC VIOLENCE RELATED     ALCOHOL
RELATED



From the above i have to count

Alcohol, Drugs and Mental Illness
Alcohol and Drugs Related
Alcohol and Mental Illness Related
Alcohol Related
Drug Related
Mental Illness Related
Mental Illness and Drug Related
No Associated Factor

Can you help me please?

thanks
regards
thara














_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

The information contained in this email is intended for the named recipient(s)
only. It may contain private, confidential, copyright or legally privileged
information.  If you are not the intended recipient or you have received this
email by mistake, please reply to the author and delete this email immediately.
You must not copy, print, forward or distribute this email, nor place reliance
on its contents. This email and any attachment have been virus scanned. However,
you are requested to conduct a virus scan as well.  No liability is accepted
for any loss or damage resulting from a computer virus, or resulting from a delay
or defect in transmission of this email or any attached file. This email does not
constitute a representation by the NSW Police Force unless the author is legally
entitled to do so.
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?"
Reply | Threaded
Open this post in threaded view
|

Re: Fw: Help with selecting records - reply to David Marso

Bruce Weaver
Administrator
Is anyone else getting a bit dizzy looking at that?  Good thing I'm sitting down.  ;-)


David Marso wrote
Hi Thara,
  I hope the following makes some sense.
 The previous syntax of course cannot directly apply as it is designed only for binary situations.  This one can be readily generalized to almost any situation similar to yours.
Please study this and do the RTFM thing if any of it is not familiar.  Very powerful technique.
I call it the Slice and Dice/Splatter/Mop Up method SADAMU for short (I just made that up).
HTH, David
---
DATA LIST LIST (",")  /ID (F2) A1 (A255) A2 (A255) A3 (A255) .
BEGIN DATA
1, ,MENTAL ILLNESS RELATED        DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED ,
2, MENTAL ILLNESS RELATED        ALCOHOL RELATED                  DOMESTIC VIOLENCE RELATED , ,DRUG RELATED                  DOMESTIC VIOLENCE RELATED
3, ,DOMESTIC VIOLENCE RELATED     SEXUAL ABUSE RELATED          ALCOHOL RELATED
4,DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED               MENTAL ILLNESS RELATED , ,ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     DRUG RELATED
5, ,ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     MENTAL ILLNESS RELATED ,
6,DRUG RELATED                     DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED , ,DRUG RELATED                  MENTAL ILLNESS RELATED        DOMESTIC VIOLENCE RELATED
7, ,DRUG RELATED                  ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED ,
8,MENTAL ILLNESS RELATED        DRUG RELATED                  DOMESTIC VIOLENCE RELATED , ,PERSONAL VIOLENCE RELATED     ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED
9, ,TRANSIT RELATED               ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED .
10,TRANSIT RELATED               DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED , ,
END DATA.
LIST.
* PARSE the individual fields into parts /General parser for strings*.
DO REPEAT V=A1 TO A3 /VEC=V_A1_ V_A2_ V_A3_ .
+  COMPUTE V=LTRIM(V).
+  VECTOR VEC(3,A30).
+  COMPUTE #I=1.
+  LOOP.
+    COMPUTE #=INDEX(V,"RELATED").
+    DO IF # GT 0.
+      COMPUTE VEC(#I)=SUBSTR(V,1,#-1).
+      COMPUTE V=LTRIM(SUBSTR(V,#+7)).
+      COMPUTE #I=#I+1.
+    END IF.
+  END LOOP IF # EQ 0.
END REPEAT.
********.
* GO WIDE to LONG /OLD SKOOL BV2C logic *.
VECTOR V=V_A1_1 TO V_A3_3.
STRING CLASS(A30).
LOOP Source=1 TO 3.
+  LOOP INDEX=1 TO 3.
+    COMPUTE CLASS=LTRIM(RTRIM( V((Source-1)*3+INDEX))).
+    DO IF LTRIM(CLASS) NE " ".
+      XSAVE OUTFILE "C:\LONG.SAV" / KEEP ID SOURCE INDEX CLASS.
+    END IF.
+  END LOOP.
END LOOP.
EXECUTE.
****.
* OBTAIN CANONICAL ORDERINGS and concatenate *.
GET FILE "C:\LONG.SAV" .
SORT CASES BY ID SOURCE CLASS.
STRING COMBOS (A12).
IF $CASENUM  EQ 1 OR ( ID NE LAG(ID) OR SOURCE NE LAG(SOURCE)) COMBOS=SUBSTR(CLASS,1,2).
IF ID=LAG(ID) AND SOURCE=LAG(SOURCE) COMBOS=CONCAT(RTRIM(LAG(COMBOS)),"|",SUBSTR(CLASS,1,2)).

* SNAG the final canonical combo and drop the dust *.
MATCH FILES / FILE * /BY ID SOURCE/ LAST=FLAGGED / KEEP ID SOURCE COMBOS .
SELECT IF FLAGGED.
LIST.

ID   SOURCE COMBOS       FLAGGED

 1     2.00 AL|DO|ME        1
 2     1.00 AL|DO|ME        1
 2     3.00 DO|DR           1
 3     2.00 AL|DO|SE        1
 4     1.00 AL|DO|ME        1
 4     3.00 AL|DO|DR        1
 5     2.00 AL|DO|ME        1
 6     1.00 AL|DO|DR        1
 6     3.00 DO|DR|ME        1
 7     2.00 AL|DO|DR        1
 8     1.00 DO|DR|ME        1
 8     3.00 AL|DO|PE        1
 9     2.00 AL|DO|TR        1
10     1.00 AL|DO|TR        1


Number of cases read:  14    Number of cases listed:  14
 
Thara Vardhan wrote
Hi David

Thank you so much - the syntax you have sent works perfectly.
Yes you are absolutely right about CASESTOVARS. I could not use it b'coz i
had too many variables and records.
Interestingly I have to use the same logic for selecting records from
another file too. However that file has 3 descriptive variables that are
not recorded in any systematic order.
Example: All records are domestic or personal violence related.

Assoc1
Assoc2
Assoc3

MENTAL ILLNESS RELATED        DOMESTIC VIOLENCE RELATED     ALCOHOL
RELATED

MENTAL ILLNESS RELATED        ALCOHOL RELATED                  DOMESTIC
VIOLENCE RELATED

DRUG RELATED                  DOMESTIC VIOLENCE RELATED

DOMESTIC VIOLENCE RELATED     SEXUAL ABUSE RELATED          ALCOHOL
RELATED

DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED               MENTAL ILLNESS
RELATED

ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     DRUG RELATED

ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     MENTAL ILLNESS
RELATED

DRUG RELATED                     DOMESTIC VIOLENCE RELATED     ALCOHOL
RELATED

DRUG RELATED                  MENTAL ILLNESS RELATED        DOMESTIC
VIOLENCE RELATED

DRUG RELATED                  ALCOHOL RELATED               DOMESTIC
VIOLENCE RELATED

MENTAL ILLNESS RELATED        DRUG RELATED                  DOMESTIC
VIOLENCE RELATED

PERSONAL VIOLENCE RELATED     ALCOHOL RELATED               DOMESTIC
VIOLENCE RELATED

TRANSIT RELATED               ALCOHOL RELATED               DOMESTIC
VIOLENCE RELATED

TRANSIT RELATED               DOMESTIC VIOLENCE RELATED     ALCOHOL
RELATED



From the above i have to count

Alcohol, Drugs and Mental Illness
Alcohol and Drugs Related
Alcohol and Mental Illness Related
Alcohol Related
Drug Related
Mental Illness Related
Mental Illness and Drug Related
No Associated Factor

Can you help me please?

thanks
regards
thara














_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

The information contained in this email is intended for the named recipient(s)
only. It may contain private, confidential, copyright or legally privileged
information.  If you are not the intended recipient or you have received this
email by mistake, please reply to the author and delete this email immediately.
You must not copy, print, forward or distribute this email, nor place reliance
on its contents. This email and any attachment have been virus scanned. However,
you are requested to conduct a virus scan as well.  No liability is accepted
for any loss or damage resulting from a computer virus, or resulting from a delay
or defect in transmission of this email or any attached file. This email does not
constitute a representation by the NSW Police Force unless the author is legally
entitled to do so.
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Fw: Help with selecting records - reply to David Marso

David Marso
Administrator
In reply to this post by David Marso
*A bit less cognitive load and no temp file required *.
** Untested VARSTOCASES equivalent *.

VARSTOCASES
   / MAKE Class FROM V_A1_1 TO V_A3_3   / INDEX Source(3) Index(3)  / KEEP ID.

* Added to select only desired types *.
SELECT IF ANY(SUBSTR(Class,1,2),"AL","DR","ME").

* OBTAIN CANONICAL ORDERINGS and concatenate *.
SORT CASES BY ID SOURCE CLASS.
STRING COMBOS (A12).
*Slightly modified following line  *UNTESTED* .
IF ANY($CASENUM EQ 1,  ID NE LAG(ID), SOURCE NE LAG(SOURCE) ) COMBOS=SUBSTR(CLASS,1,2).
IF ID=LAG(ID) AND SOURCE=LAG(SOURCE) COMBOS=CONCAT(RTRIM(LAG(COMBOS)),"&",SUBSTR(CLASS,1,2)).

* SNAG the final canonical combo and drop the dust *.
MATCH FILES / FILE * /BY ID SOURCE/ LAST=FLAGGED / KEEP ID SOURCE COMBOS .
SELECT IF FLAGGED.
LIST.

David Marso wrote
Hi Thara,
  I hope the following makes some sense.
 The previous syntax of course cannot directly apply as it is designed only for binary situations.  This one can be readily generalized to almost any situation similar to yours.
Please study this and do the RTFM thing if any of it is not familiar.  Very powerful technique.
I call it the Slice and Dice/Splatter/Mop Up method SADAMU for short (I just made that up).
HTH, David
---
DATA LIST LIST (",")  /ID (F2) A1 (A255) A2 (A255) A3 (A255) .
BEGIN DATA
1, ,MENTAL ILLNESS RELATED        DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED ,
2, MENTAL ILLNESS RELATED        ALCOHOL RELATED                  DOMESTIC VIOLENCE RELATED , ,DRUG RELATED                  DOMESTIC VIOLENCE RELATED
3, ,DOMESTIC VIOLENCE RELATED     SEXUAL ABUSE RELATED          ALCOHOL RELATED
4,DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED               MENTAL ILLNESS RELATED , ,ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     DRUG RELATED
5, ,ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     MENTAL ILLNESS RELATED ,
6,DRUG RELATED                     DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED , ,DRUG RELATED                  MENTAL ILLNESS RELATED        DOMESTIC VIOLENCE RELATED
7, ,DRUG RELATED                  ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED ,
8,MENTAL ILLNESS RELATED        DRUG RELATED                  DOMESTIC VIOLENCE RELATED , ,PERSONAL VIOLENCE RELATED     ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED
9, ,TRANSIT RELATED               ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED .
10,TRANSIT RELATED               DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED , ,
END DATA.
LIST.
* PARSE the individual fields into parts /General parser for strings*.
DO REPEAT V=A1 TO A3 /VEC=V_A1_ V_A2_ V_A3_ .
+  COMPUTE V=LTRIM(V).
+  VECTOR VEC(3,A30).
+  COMPUTE #I=1.
+  LOOP.
+    COMPUTE #=INDEX(V,"RELATED").
+    DO IF # GT 0.
+      COMPUTE VEC(#I)=SUBSTR(V,1,#-1).
+      COMPUTE V=LTRIM(SUBSTR(V,#+7)).
+      COMPUTE #I=#I+1.
+    END IF.
+  END LOOP IF # EQ 0.
END REPEAT.
********.
* GO WIDE to LONG /OLD SKOOL BV2C logic *.
VECTOR V=V_A1_1 TO V_A3_3.
STRING CLASS(A30).
LOOP Source=1 TO 3.
+  LOOP INDEX=1 TO 3.
+    COMPUTE CLASS=LTRIM(RTRIM( V((Source-1)*3+INDEX))).
+    DO IF LTRIM(CLASS) NE " ".
+      XSAVE OUTFILE "C:\LONG.SAV" / KEEP ID SOURCE INDEX CLASS.
+    END IF.
+  END LOOP.
END LOOP.
EXECUTE.
****.
* OBTAIN CANONICAL ORDERINGS and concatenate *.
GET FILE "C:\LONG.SAV" .
SORT CASES BY ID SOURCE CLASS.
STRING COMBOS (A12).
IF $CASENUM  EQ 1 OR ( ID NE LAG(ID) OR SOURCE NE LAG(SOURCE)) COMBOS=SUBSTR(CLASS,1,2).
IF ID=LAG(ID) AND SOURCE=LAG(SOURCE) COMBOS=CONCAT(RTRIM(LAG(COMBOS)),"|",SUBSTR(CLASS,1,2)).

* SNAG the final canonical combo and drop the dust *.
MATCH FILES / FILE * /BY ID SOURCE/ LAST=FLAGGED / KEEP ID SOURCE COMBOS .
SELECT IF FLAGGED.
LIST.

ID   SOURCE COMBOS       FLAGGED

 1     2.00 AL|DO|ME        1
 2     1.00 AL|DO|ME        1
 2     3.00 DO|DR           1
 3     2.00 AL|DO|SE        1
 4     1.00 AL|DO|ME        1
 4     3.00 AL|DO|DR        1
 5     2.00 AL|DO|ME        1
 6     1.00 AL|DO|DR        1
 6     3.00 DO|DR|ME        1
 7     2.00 AL|DO|DR        1
 8     1.00 DO|DR|ME        1
 8     3.00 AL|DO|PE        1
 9     2.00 AL|DO|TR        1
10     1.00 AL|DO|TR        1


Number of cases read:  14    Number of cases listed:  14
 
Thara Vardhan wrote
Hi David

Thank you so much - the syntax you have sent works perfectly.
Yes you are absolutely right about CASESTOVARS. I could not use it b'coz i
had too many variables and records.
Interestingly I have to use the same logic for selecting records from
another file too. However that file has 3 descriptive variables that are
not recorded in any systematic order.
Example: All records are domestic or personal violence related.

Assoc1
Assoc2
Assoc3

MENTAL ILLNESS RELATED        DOMESTIC VIOLENCE RELATED     ALCOHOL
RELATED

MENTAL ILLNESS RELATED        ALCOHOL RELATED                  DOMESTIC
VIOLENCE RELATED

DRUG RELATED                  DOMESTIC VIOLENCE RELATED

DOMESTIC VIOLENCE RELATED     SEXUAL ABUSE RELATED          ALCOHOL
RELATED

DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED               MENTAL ILLNESS
RELATED

ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     DRUG RELATED

ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     MENTAL ILLNESS
RELATED

DRUG RELATED                     DOMESTIC VIOLENCE RELATED     ALCOHOL
RELATED

DRUG RELATED                  MENTAL ILLNESS RELATED        DOMESTIC
VIOLENCE RELATED

DRUG RELATED                  ALCOHOL RELATED               DOMESTIC
VIOLENCE RELATED

MENTAL ILLNESS RELATED        DRUG RELATED                  DOMESTIC
VIOLENCE RELATED

PERSONAL VIOLENCE RELATED     ALCOHOL RELATED               DOMESTIC
VIOLENCE RELATED

TRANSIT RELATED               ALCOHOL RELATED               DOMESTIC
VIOLENCE RELATED

TRANSIT RELATED               DOMESTIC VIOLENCE RELATED     ALCOHOL
RELATED



From the above i have to count

Alcohol, Drugs and Mental Illness
Alcohol and Drugs Related
Alcohol and Mental Illness Related
Alcohol Related
Drug Related
Mental Illness Related
Mental Illness and Drug Related
No Associated Factor

Can you help me please?

thanks
regards
thara














_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

The information contained in this email is intended for the named recipient(s)
only. It may contain private, confidential, copyright or legally privileged
information.  If you are not the intended recipient or you have received this
email by mistake, please reply to the author and delete this email immediately.
You must not copy, print, forward or distribute this email, nor place reliance
on its contents. This email and any attachment have been virus scanned. However,
you are requested to conduct a virus scan as well.  No liability is accepted
for any loss or damage resulting from a computer virus, or resulting from a delay
or defect in transmission of this email or any attached file. This email does not
constitute a representation by the NSW Police Force unless the author is legally
entitled to do so.
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?"
Reply | Threaded
Open this post in threaded view
|

Re: Fw: Help with selecting records - reply to David Marso

David Marso
Administrator
In reply to this post by Bruce Weaver

Bruce,
  Get a strong cup of coffee, let it hit you then it should be as clear as mud .
OTOH, I just posted an untested V2C version which is a bit cleaner and less cognitively challenging ;-)
Of course run the PreRamble first to parse the 3 "messy fields".
--
What have we learned here today?
Don't look at my VECTOR/LOOP biz until after coffee # 1.  Or sit down when you read it.
For some reason I still do the LOOP/XSAVE biz rather than V2C even though I helped design the damned proc (didn't have the manual avail and I'd already written the LOOP code and it was early AM/late night).
David
---
Bruce Weaver wrote
Is anyone else getting a bit dizzy looking at that?  Good thing I'm sitting down.  ;-)


David Marso wrote
Hi Thara,
  I hope the following makes some sense.
 The previous syntax of course cannot directly apply as it is designed only for binary situations.  This one can be readily generalized to almost any situation similar to yours.
Please study this and do the RTFM thing if any of it is not familiar.  Very powerful technique.
I call it the Slice and Dice/Splatter/Mop Up method SADAMU for short (I just made that up).
HTH, David
---
DATA LIST LIST (",")  /ID (F2) A1 (A255) A2 (A255) A3 (A255) .
BEGIN DATA
1, ,MENTAL ILLNESS RELATED        DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED ,
2, MENTAL ILLNESS RELATED        ALCOHOL RELATED                  DOMESTIC VIOLENCE RELATED , ,DRUG RELATED                  DOMESTIC VIOLENCE RELATED
3, ,DOMESTIC VIOLENCE RELATED     SEXUAL ABUSE RELATED          ALCOHOL RELATED
4,DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED               MENTAL ILLNESS RELATED , ,ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     DRUG RELATED
5, ,ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     MENTAL ILLNESS RELATED ,
6,DRUG RELATED                     DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED , ,DRUG RELATED                  MENTAL ILLNESS RELATED        DOMESTIC VIOLENCE RELATED
7, ,DRUG RELATED                  ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED ,
8,MENTAL ILLNESS RELATED        DRUG RELATED                  DOMESTIC VIOLENCE RELATED , ,PERSONAL VIOLENCE RELATED     ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED
9, ,TRANSIT RELATED               ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED .
10,TRANSIT RELATED               DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED , ,
END DATA.
LIST.
* PARSE the individual fields into parts /General parser for strings*.
DO REPEAT V=A1 TO A3 /VEC=V_A1_ V_A2_ V_A3_ .
+  COMPUTE V=LTRIM(V).
+  VECTOR VEC(3,A30).
+  COMPUTE #I=1.
+  LOOP.
+    COMPUTE #=INDEX(V,"RELATED").
+    DO IF # GT 0.
+      COMPUTE VEC(#I)=SUBSTR(V,1,#-1).
+      COMPUTE V=LTRIM(SUBSTR(V,#+7)).
+      COMPUTE #I=#I+1.
+    END IF.
+  END LOOP IF # EQ 0.
END REPEAT.
********.
* GO WIDE to LONG /OLD SKOOL BV2C logic *.
VECTOR V=V_A1_1 TO V_A3_3.
STRING CLASS(A30).
LOOP Source=1 TO 3.
+  LOOP INDEX=1 TO 3.
+    COMPUTE CLASS=LTRIM(RTRIM( V((Source-1)*3+INDEX))).
+    DO IF LTRIM(CLASS) NE " ".
+      XSAVE OUTFILE "C:\LONG.SAV" / KEEP ID SOURCE INDEX CLASS.
+    END IF.
+  END LOOP.
END LOOP.
EXECUTE.
****.
* OBTAIN CANONICAL ORDERINGS and concatenate *.
GET FILE "C:\LONG.SAV" .
SORT CASES BY ID SOURCE CLASS.
STRING COMBOS (A12).
IF $CASENUM  EQ 1 OR ( ID NE LAG(ID) OR SOURCE NE LAG(SOURCE)) COMBOS=SUBSTR(CLASS,1,2).
IF ID=LAG(ID) AND SOURCE=LAG(SOURCE) COMBOS=CONCAT(RTRIM(LAG(COMBOS)),"|",SUBSTR(CLASS,1,2)).

* SNAG the final canonical combo and drop the dust *.
MATCH FILES / FILE * /BY ID SOURCE/ LAST=FLAGGED / KEEP ID SOURCE COMBOS .
SELECT IF FLAGGED.
LIST.

ID   SOURCE COMBOS       FLAGGED

 1     2.00 AL|DO|ME        1
 2     1.00 AL|DO|ME        1
 2     3.00 DO|DR           1
 3     2.00 AL|DO|SE        1
 4     1.00 AL|DO|ME        1
 4     3.00 AL|DO|DR        1
 5     2.00 AL|DO|ME        1
 6     1.00 AL|DO|DR        1
 6     3.00 DO|DR|ME        1
 7     2.00 AL|DO|DR        1
 8     1.00 DO|DR|ME        1
 8     3.00 AL|DO|PE        1
 9     2.00 AL|DO|TR        1
10     1.00 AL|DO|TR        1


Number of cases read:  14    Number of cases listed:  14
 
Thara Vardhan wrote
Hi David

Thank you so much - the syntax you have sent works perfectly.
Yes you are absolutely right about CASESTOVARS. I could not use it b'coz i
had too many variables and records.
Interestingly I have to use the same logic for selecting records from
another file too. However that file has 3 descriptive variables that are
not recorded in any systematic order.
Example: All records are domestic or personal violence related.

Assoc1
Assoc2
Assoc3

MENTAL ILLNESS RELATED        DOMESTIC VIOLENCE RELATED     ALCOHOL
RELATED

MENTAL ILLNESS RELATED        ALCOHOL RELATED                  DOMESTIC
VIOLENCE RELATED

DRUG RELATED                  DOMESTIC VIOLENCE RELATED

DOMESTIC VIOLENCE RELATED     SEXUAL ABUSE RELATED          ALCOHOL
RELATED

DOMESTIC VIOLENCE RELATED     ALCOHOL RELATED               MENTAL ILLNESS
RELATED

ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     DRUG RELATED

ALCOHOL RELATED               DOMESTIC VIOLENCE RELATED     MENTAL ILLNESS
RELATED

DRUG RELATED                     DOMESTIC VIOLENCE RELATED     ALCOHOL
RELATED

DRUG RELATED                  MENTAL ILLNESS RELATED        DOMESTIC
VIOLENCE RELATED

DRUG RELATED                  ALCOHOL RELATED               DOMESTIC
VIOLENCE RELATED

MENTAL ILLNESS RELATED        DRUG RELATED                  DOMESTIC
VIOLENCE RELATED

PERSONAL VIOLENCE RELATED     ALCOHOL RELATED               DOMESTIC
VIOLENCE RELATED

TRANSIT RELATED               ALCOHOL RELATED               DOMESTIC
VIOLENCE RELATED

TRANSIT RELATED               DOMESTIC VIOLENCE RELATED     ALCOHOL
RELATED



From the above i have to count

Alcohol, Drugs and Mental Illness
Alcohol and Drugs Related
Alcohol and Mental Illness Related
Alcohol Related
Drug Related
Mental Illness Related
Mental Illness and Drug Related
No Associated Factor

Can you help me please?

thanks
regards
thara














_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

The information contained in this email is intended for the named recipient(s)
only. It may contain private, confidential, copyright or legally privileged
information.  If you are not the intended recipient or you have received this
email by mistake, please reply to the author and delete this email immediately.
You must not copy, print, forward or distribute this email, nor place reliance
on its contents. This email and any attachment have been virus scanned. However,
you are requested to conduct a virus scan as well.  No liability is accepted
for any loss or damage resulting from a computer virus, or resulting from a delay
or defect in transmission of this email or any attached file. This email does not
constitute a representation by the NSW Police Force unless the author is legally
entitled to do so.
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?"