|
Dear Listers,
I seem to frequently encounter this problem and I need a solution that does not seem to work with either aggregate or identify duplicate case function in SPSS. The data has many variables but I am concerned with these two variables. Data is like this ID Visit_date 1 15-MAR-2007 1 15-MAR-2007 1 15-MAR-2007 1 20-JUL-2007 2 20-JUL-2007 2 20-JUL-2007 2 31-JUL-2007 2 20-AUG-2007 2 20-AUG-2007 2 20-AUG-2007 2 12-SEP-2007 3 15-MAR-2007 I want to have a new variable that gives me the distinct count for the new visit in a new variable or variables. ID Visit_date Visit_date1 1 15-MAR-2007 2 1 15-MAR-2007 1 15-MAR-2007 1 20-JUL-2007 2 20-JUL-2007 4 2 20-JUL-2007 2 31-JUL-2007 2 20-AUG-2007 2 20-AUG-2007 2 20-AUG-2007 2 12-SEP-2007 3 15-MAR-2007 1 Or atleast flag each distinct visit date, which I can sum. Any thoughts. K. ===================== 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 |
|
How about if you create a counter variable, i.e.,
Compute counter=1. Then aggregate (break) on the date and sum the counter. Arthur Kramer, Ph.D. Director of Institutional Research New Jersey City University -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Khaleel Hussaini Sent: Friday, February 15, 2008 2:24 PM To: [hidden email] Subject: Distinct counts in enrollment data Dear Listers, I seem to frequently encounter this problem and I need a solution that does not seem to work with either aggregate or identify duplicate case function in SPSS. The data has many variables but I am concerned with these two variables. Data is like this ID Visit_date 1 15-MAR-2007 1 15-MAR-2007 1 15-MAR-2007 1 20-JUL-2007 2 20-JUL-2007 2 20-JUL-2007 2 31-JUL-2007 2 20-AUG-2007 2 20-AUG-2007 2 20-AUG-2007 2 12-SEP-2007 3 15-MAR-2007 I want to have a new variable that gives me the distinct count for the new visit in a new variable or variables. ID Visit_date Visit_date1 1 15-MAR-2007 2 1 15-MAR-2007 1 15-MAR-2007 1 20-JUL-2007 2 20-JUL-2007 4 2 20-JUL-2007 2 31-JUL-2007 2 20-AUG-2007 2 20-AUG-2007 2 20-AUG-2007 2 12-SEP-2007 3 15-MAR-2007 1 Or atleast flag each distinct visit date, which I can sum. Any thoughts. K. ===================== 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 |
|
A side issue: At 03:38 PM 2/15/2008, Arthur Kramer wrote:
>How about if you create a counter variable, i.e., > >Compute counter=1. > >Then aggregate (break) on the date and sum the counter. That works, but you don't need 'counter'. AGGREGATE functions N or NU count cases, directly. ===================== 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 Khaleel Hussaini
At 02:23 PM 2/15/2008, Khaleel Hussaini wrote:
>I want to have a new variable that gives me the distinct count for >the new visit in a new variable or variables. Or at least flag each >distinct visit date. > >|-----------------------------|---------------------------| >|Output Created |16-FEB-2008 17:24:48 | >|-----------------------------|---------------------------| >ID Visit_date > > 1 15-MAR-2007 > 1 15-MAR-2007 > 1 15-MAR-2007 > 1 20-JUL-2007 > 2 20-JUL-2007 > 2 20-JUL-2007 > 2 31-JUL-2007 > 2 20-AUG-2007 > 2 20-AUG-2007 > 2 20-AUG-2007 > 2 12-SEP-2007 > 3 15-MAR-2007 > >Number of cases read: 12 Number of cases listed: 12 I'm not clear what you want. "Visit_date1" doesn't seem to be the count of visits for that patient on that date: f it were, it's wrong for patient 1 on 15 March and patient 2 on 20 July; and has no value at all for three other visits. And it doesn't indicate the first record for a visit. Melissa's probably right, suggesting "AGGREGATE using two break variables--ID and Visit_Date". Is this anywhere near what you want? (SPSS draft output; not saved separately; test data at end.) NUMERIC IdDate# (F3). VAR LABEL IdDate# 'Unique # for ID-Date combinations'. * ................................................... . * WARNING #1: Adding data and re-running this code . * will usually change the numbers assigned to . * existing ID-Date pairs. . * ................................................... . * WARNING #2: The following code won't work if either . * either ID or Visit_Date have missing data anywhere. . * Various fixes are possible, but which to use . * depends on what behaviour is desired in this case. . * ................................................... . DO IF $CASENUM EQ 1. . COMPUTE IdDate# = 1. ELSE IF ID EQ LAG(ID) & Visit_Date EQ LAG(Visit_Date). . COMPUTE IdDate# = LAG(IdDate#). ELSE. . COMPUTE IdDate# = LAG(IdDate#). END IF. AGGREGATE OUTFILE* MODE=ADDVARIABLES /BREAK=ID Visit_Date /NRecords 'Number of records for this ID-Date combination' = NU. LIST. List |-----------------------------|---------------------------| |Output Created |16-FEB-2008 17:24:49 | |-----------------------------|---------------------------| ID Visit_date IdDate# NRecords 1 15-MAR-2007 1 3 1 15-MAR-2007 1 3 1 15-MAR-2007 1 3 1 20-JUL-2007 1 1 2 20-JUL-2007 1 2 2 20-JUL-2007 1 2 2 31-JUL-2007 1 1 2 20-AUG-2007 1 3 2 20-AUG-2007 1 3 2 20-AUG-2007 1 3 2 12-SEP-2007 1 1 3 15-MAR-2007 1 1 Number of cases read: 12 Number of cases listed: 12 ============================= APPENDIX: Test data, and code ============================= DATA LIST LIST / ID Visit_date (F2 DATE11). BEGIN DATA 1 15-MAR-2007 1 15-MAR-2007 1 15-MAR-2007 1 20-JUL-2007 2 20-JUL-2007 2 20-JUL-2007 2 31-JUL-2007 2 20-AUG-2007 2 20-AUG-2007 2 20-AUG-2007 2 12-SEP-2007 3 15-MAR-2007 END DATA. LIST. NUMERIC IdDate# (F3). VAR LABEL IdDate# 'Unique # for ID-Date combinations'. * ................................................... . * WARNING #1: Adding data and re-running this code . * will usually change the numbers assigned to . * existing ID-Date pairs. . * ................................................... . * WARNING #2: The following code won't work if either . * either ID or Visit_Date have missing data anywhere. . * Various fixes are possible, but which to use . * depends on what behaviour is desired in this case. . * ................................................... . DO IF $CASENUM EQ 1. . COMPUTE IdDate# = 1. ELSE IF ID EQ LAG(ID) & Visit_Date EQ LAG(Visit_Date). . COMPUTE IdDate# = LAG(IdDate#). ELSE. . COMPUTE IdDate# = LAG(IdDate#). END IF. AGGREGATE OUTFILE* MODE=ADDVARIABLES /BREAK=ID Visit_Date /NRecords 'Number of records for this ID-Date combination' = NU. 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 |
|
Hi all,
Two quick questions. I'm running on v.11 (home) and v.14 (work). I was curious as to whether, using syntax, one can (a) save an output file to a given path, similar to how one can save a datafile to a given path using the SAVE OUTFILE command; (b) close an open output file using a syntax command. I've browsed the user guides and not seen anything, and have never seen anything mentioned on here. Such commands would be quite useful given that it doesn't take too many procedures, depending on what one's doing, to create a rather large, bulky output file. Regards, Matt --------------------------------- Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. ===================== 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 v 11 -14, there is no syntax way of controlling the Viewer files. SPSS 15 introduced the Output commands
OUTPUT NEW OUTPUT CLOSE OUTPUT OPEN OUTPUT SAVE OUTPUT DISPLAY OUTPUT ACTIVATE In older versions, you can control the Viewer documents with SaxBasic, but it is tricky to synchronize, say, closing a Viewer file at an exact point in the syntax. In SPSS 14, however, via programmability, you can save and close the designated output file using methods in the viewer module, and these synchronize properly with syntax (it took some work to make that happen.) For example, you can include this in your syntax stream. begin program. import viewer app = viewer.spssapp() app.SaveDesignatedOutput("c:/temp/myoutput.spo") app.CloseDesignatedOutput() end program. Additional SPSS output will automatically appear in a new Viewer document. This module also provides a method to export the designated Viewer document to Excel, Word, html, etc. The viewer module requires, of course, Python and the plugin from Developer Central along with some other downloads outlined in that module. These methods, are, of course, superseded in SPSS 15. HTH. Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Matthew Reeder Sent: Saturday, February 16, 2008 4:41 PM To: [hidden email] Subject: [SPSSX-L] Editing output using syntax Hi all, Two quick questions. I'm running on v.11 (home) and v.14 (work). I was curious as to whether, using syntax, one can (a) save an output file to a given path, similar to how one can save a datafile to a given path using the SAVE OUTFILE command; (b) close an open output file using a syntax command. I've browsed the user guides and not seen anything, and have never seen anything mentioned on here. Such commands would be quite useful given that it doesn't take too many procedures, depending on what one's doing, to create a rather large, bulky output file. Regards, Matt --------------------------------- Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. ===================== 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 |
| Free forum by Nabble | Edit this page |
