Hi SPSS-ers
I have 2 sets of date variables (1) one is admissions and discharges into one system the other (2) is admissions and discharges into another system. So the data looks like this: ID ADM1 DSCH1 ADM2 DSCH2 123 12/11/06 12/15/06 11/15/06 11/23/06 123 12/25/06 12/30/06 11/28/06 12/1/06 344 6/7/05 7/7/05 4/4/05 4/28/05 344 12/31/05 1/12/06 8/8/05 8/10/05 What I would like to be able to do is either find a way to combine them, in order by adm date, into one variable, or figure out a way to tell the number of days between last discharge from either system and next admission into either system. Any thoughts? Thanks, -- Christopher Fisher, M.A., M.Phil. Senior Research Assistant Criminal Justice Research & Evaluation Center John Jay College of Criminal Justice 555 West 57th Street, Suite 605 New York, New York 10019 212-237-8000 (x2145) 212-237-8644 (fax) |
This seems to be a VarsToCases question---that is going from wide
(horizontal) to long (vertical). If you end up with ID Adm Dsch 123 12/11/06 12/15/06 123 11/15/06 11/23/06 123 12/25/06 12/30/06 123 11/28/06 12/1/06 344 6/7/05 7/7/05 344 4/4/05 4/28/05 344 12/31/05 1/12/06 344 8/8/05 8/10/05 Then you can easily sort them. When we look at time from discharge to next admission, we often use a lag function to calculate E.g. If (ID=lag(ID)) timesince=DATEDIFF(adm, lag(dsch), "DAYS"). (this woud create a new variable on the row with the CURRENT admission for the Time SINCE the last discharge). To turn it around, sort the cases in reverse order by admission and switch the calculation to be the Time UNTIL the next admission. (I'm sure there are other solutions as well :-) Melissa -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Chris Fisher Sent: Thursday, December 14, 2006 3:41 PM To: [hidden email] Subject: [SPSSX-L] An interesting (and I think new) date question Hi SPSS-ers I have 2 sets of date variables (1) one is admissions and discharges into one system the other (2) is admissions and discharges into another system. So the data looks like this: ID ADM1 DSCH1 ADM2 DSCH2 123 12/11/06 12/15/06 11/15/06 11/23/06 123 12/25/06 12/30/06 11/28/06 12/1/06 344 6/7/05 7/7/05 4/4/05 4/28/05 344 12/31/05 1/12/06 8/8/05 8/10/05 What I would like to be able to do is either find a way to combine them, in order by adm date, into one variable, or figure out a way to tell the number of days between last discharge from either system and next admission into either system. Any thoughts? Thanks, -- Christopher Fisher, M.A., M.Phil. Senior Research Assistant Criminal Justice Research & Evaluation Center John Jay College of Criminal Justice 555 West 57th Street, Suite 605 New York, New York 10019 212-237-8000 (x2145) 212-237-8644 (fax) PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. |
In reply to this post by Chris Fisher-2
All,
I'm working on a macro (my first, actually) and have run into problems. What I want to macro-ize is the following code, with a filename filled in. * READ AND SAVE I:\FWT\ANALYSES FILES. DATA LIST FILE='I:\FWT\ANALYSES\RSA06TOM\FFM1\FF1SA0.INP' / ILINE 1-80(A). EXECUTE. COMPUTE REC=$CASENUM. SAVE OUTFILE='C:\TEMP\ANALYSES\FF1SA0.SAV'. Now the macro SET MPRINT=ON. SET MEXPAND=ON. DEFINE !READ(DIR=!TOKENS(1)/FNAME=!TOKENS(1)/EXT=!TOKENS(1)). * READ AND SAVE I:\FWT\ANALYSES FILES. DATA LIST FILE='!CONCAT(I:\FWT\ANALYSES\RSA06TOM\,!DIR,\,!FNAME,.,!EXT)' / ILINE 1-80(A). EXECUTE. COMPUTE REC=$CASENUM. SAVE OUTFILE='!CONCAT(C:\TEMP\ANALYSES\,!FNAME,.SAV)'. !ENDDEFINE. Next, the invocation. !READ DIR=FFM1 FNAME=FF1SA0 EXT=INP. The macro appears to compile correctly, i.e., I get no errors. But when invoked I get an error: >Error # 34 in column 16. Text: !CONCAT(I:\FWT\ANALYSES\RSA06TOM\,!DIR,\,! >SPSS cannot access a file with the given file specification. The file >specification is either syntactically invalid, specifies an invalid drive, >specifies a protected directory, specifies a protected file, or specifies a >non-sharable file. >This command not executed. I interpret this message to mean that something is wrong with how the !concat expression is being expanded and concantenated. I know the file is there because I ran a normal data list statement and the file opened ok. Can someone help me with this? Second, is there a way that the expanded values can be made to print out? Is there a way to display the result of !CONCAT(I:\FWT\ANALYSES\RSA06TOM\,!DIR,\,!FNAME) AS THE MACRO EXECUTES? Thanks, Gene Maguin |
Hi Gene -
Just from a quick look, might you replace the line FILE='!CONCAT(I:\FWT\ANALYSES\RSA06TOM\,!DIR,\,!FNAME,.,!EXT)' with something like FILE=!QUOTE(!CONCAT(!UNQUOTE(I:\FWT\ANALYSES\RSA06TOM\),!DIR,"\",!FNAME,".", !EXT)) Peter Link VA San Diego Healthcare System -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Gene Maguin Sent: Thursday, December 14, 2006 2:45 PM To: [hidden email] Subject: Macro problems All, I'm working on a macro (my first, actually) and have run into problems. What I want to macro-ize is the following code, with a filename filled in. * READ AND SAVE I:\FWT\ANALYSES FILES. DATA LIST FILE='I:\FWT\ANALYSES\RSA06TOM\FFM1\FF1SA0.INP' / ILINE 1-80(A). EXECUTE. COMPUTE REC=$CASENUM. SAVE OUTFILE='C:\TEMP\ANALYSES\FF1SA0.SAV'. Now the macro SET MPRINT=ON. SET MEXPAND=ON. DEFINE !READ(DIR=!TOKENS(1)/FNAME=!TOKENS(1)/EXT=!TOKENS(1)). * READ AND SAVE I:\FWT\ANALYSES FILES. DATA LIST FILE='!CONCAT(I:\FWT\ANALYSES\RSA06TOM\,!DIR,\,!FNAME,.,!EXT)' / ILINE 1-80(A). EXECUTE. COMPUTE REC=$CASENUM. SAVE OUTFILE='!CONCAT(C:\TEMP\ANALYSES\,!FNAME,.SAV)'. !ENDDEFINE. Next, the invocation. !READ DIR=FFM1 FNAME=FF1SA0 EXT=INP. The macro appears to compile correctly, i.e., I get no errors. But when invoked I get an error: >Error # 34 in column 16. Text: !CONCAT(I:\FWT\ANALYSES\RSA06TOM\,!DIR,\,! >SPSS cannot access a file with the given file specification. The file >specification is either syntactically invalid, specifies an invalid drive, >specifies a protected directory, specifies a protected file, or specifies a >non-sharable file. >This command not executed. I interpret this message to mean that something is wrong with how the !concat expression is being expanded and concantenated. I know the file is there because I ran a normal data list statement and the file opened ok. Can someone help me with this? Second, is there a way that the expanded values can be made to print out? Is there a way to display the result of !CONCAT(I:\FWT\ANALYSES\RSA06TOM\,!DIR,\,!FNAME) AS THE MACRO EXECUTES? Thanks, Gene Maguin |
In reply to this post by Maguin, Eugene
Sorry the line should read something like
FILE=!QUOTE(!CONCAT("I:\FWT\ANALYSES\RSA06TOM\",!DIR,"\",!FNAME,".",!EXT)) Peter Link VA San Diego Healthcare System -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]]On Behalf Of Gene Maguin Sent: Thursday, December 14, 2006 2:45 PM To: [hidden email] Subject: Macro problems All, I'm working on a macro (my first, actually) and have run into problems. What I want to macro-ize is the following code, with a filename filled in. * READ AND SAVE I:\FWT\ANALYSES FILES. DATA LIST FILE='I:\FWT\ANALYSES\RSA06TOM\FFM1\FF1SA0.INP' / ILINE 1-80(A). EXECUTE. COMPUTE REC=$CASENUM. SAVE OUTFILE='C:\TEMP\ANALYSES\FF1SA0.SAV'. Now the macro SET MPRINT=ON. SET MEXPAND=ON. DEFINE !READ(DIR=!TOKENS(1)/FNAME=!TOKENS(1)/EXT=!TOKENS(1)). * READ AND SAVE I:\FWT\ANALYSES FILES. DATA LIST FILE='!CONCAT(I:\FWT\ANALYSES\RSA06TOM\,!DIR,\,!FNAME,.,!EXT)' / ILINE 1-80(A). EXECUTE. COMPUTE REC=$CASENUM. SAVE OUTFILE='!CONCAT(C:\TEMP\ANALYSES\,!FNAME,.SAV)'. !ENDDEFINE. Next, the invocation. !READ DIR=FFM1 FNAME=FF1SA0 EXT=INP. The macro appears to compile correctly, i.e., I get no errors. But when invoked I get an error: >Error # 34 in column 16. Text: !CONCAT(I:\FWT\ANALYSES\RSA06TOM\,!DIR,\,! >SPSS cannot access a file with the given file specification. The file >specification is either syntactically invalid, specifies an invalid drive, >specifies a protected directory, specifies a protected file, or specifies a >non-sharable file. >This command not executed. I interpret this message to mean that something is wrong with how the !concat expression is being expanded and concantenated. I know the file is there because I ran a normal data list statement and the file opened ok. Can someone help me with this? Second, is there a way that the expanded values can be made to print out? Is there a way to display the result of !CONCAT(I:\FWT\ANALYSES\RSA06TOM\,!DIR,\,!FNAME) AS THE MACRO EXECUTES? Thanks, Gene Maguin |
Free forum by Nabble | Edit this page |