|
Hi all! I need help with 2 questions.
Thank you Richard Ristow and ViAnn Beadle. The loop problem is solved, thank you. Let me clarify the other two questions. The example below are simplified examples of very large files. In the first file (TestList.sav) forms list of names of variables (as a string XList when iD=2) that will become arguments for the AGGREGATE specifications for another file (TestX.sav). DATA LIST /iD (F1) Pos (F3) X 5-6(A). BEGIN DATA 0 1 1 1 X1 2 1 X2 3 0 X3 END DATA. STRING XList (A255). COMPUTE XList="". LOOP #J=1 TO iD. IF iD=#J XList=LTRIM(CONCAT(RTRIM(LTRIM(LAG(XList))), ' ',RTRIM(LTRIM (X)))). END LOOP IF (Pos=0). LIST. SAVE OUTFILE='c:\SPSS\TestList.sav'. Question 1: How can I copy the value of Xlist at iD = 2 to Xlist at iD = 0? For example the following doesn't work for strings: CREATE XList1 = LEAD(XList, 2). Question 2: The 2nd file (TestX.sav) contains the variables to be aggregated. I need to assign to the AGGREGATE the list of variables for the TestX.sav file, as values of XList variable, when iD =2 (calculated in the TestList.sav file). DATA LIST LIST/BreakX(F1) X1(F1) X2(F1) X3(F1). BEGIN DATA 1 1 2 1 1 1 0 0 2 1 0 1 2 0 2 2 END DATA. LIST. SAVE OUTFILE='c:\SPSS\TestX.sav'. AGGREGATE /OUTFILE = 'c:\SPSS\aggTestX.sav' /BREAK = BreakX /X1 X2 = sum (X1 X2). /*<---------- How to pass the arguments here from another file?. We can also use DEFINE, but there is the same problem. DEFINE aggList (!POSITIONAL !enclose( '(' , ')' )). AGGREGATE /OUTFILE = 'c:\SPSS\aggTEST.sav' /BREAK = BreakX /!1 = sum (!1). !ENDDEFINE. aggList(X1 X2). /*<---------- How to pass the arguments here from another file?. Thank you very much for your help. ===================== 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 |
|
1. As I said before LEAD copies the value of the current case to the
following case. You want the LAG function which copies the value of a prior case to the current case. 2. Why are you trying to drive syntax by storing values in a data file? This I find very strange. You could use Python or you could write syntax to a syntax file and then include that. AGGREGATE works on only data file at a time. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Simon Levin Sent: Monday, November 12, 2007 11:26 AM To: [hidden email] Subject: 3 Short Questions con't... Hi all! I need help with 2 questions. Thank you Richard Ristow and ViAnn Beadle. The loop problem is solved, thank you. Let me clarify the other two questions. The example below are simplified examples of very large files. In the first file (TestList.sav) forms list of names of variables (as a string XList when iD=2) that will become arguments for the AGGREGATE specifications for another file (TestX.sav). DATA LIST /iD (F1) Pos (F3) X 5-6(A). BEGIN DATA 0 1 1 1 X1 2 1 X2 3 0 X3 END DATA. STRING XList (A255). COMPUTE XList="". LOOP #J=1 TO iD. IF iD=#J XList=LTRIM(CONCAT(RTRIM(LTRIM(LAG(XList))), ' ',RTRIM(LTRIM (X)))). END LOOP IF (Pos=0). LIST. SAVE OUTFILE='c:\SPSS\TestList.sav'. Question 1: How can I copy the value of Xlist at iD = 2 to Xlist at iD = 0? For example the following doesn't work for strings: CREATE XList1 = LEAD(XList, 2). Question 2: The 2nd file (TestX.sav) contains the variables to be aggregated. I need to assign to the AGGREGATE the list of variables for the TestX.sav file, as values of XList variable, when iD =2 (calculated in the TestList.sav file). DATA LIST LIST/BreakX(F1) X1(F1) X2(F1) X3(F1). BEGIN DATA 1 1 2 1 1 1 0 0 2 1 0 1 2 0 2 2 END DATA. LIST. SAVE OUTFILE='c:\SPSS\TestX.sav'. AGGREGATE /OUTFILE = 'c:\SPSS\aggTestX.sav' /BREAK = BreakX /X1 X2 = sum (X1 X2). /*<---------- How to pass the arguments here from another file?. We can also use DEFINE, but there is the same problem. DEFINE aggList (!POSITIONAL !enclose( '(' , ')' )). AGGREGATE /OUTFILE = 'c:\SPSS\aggTEST.sav' /BREAK = BreakX /!1 = sum (!1). !ENDDEFINE. aggList(X1 X2). /*<---------- How to pass the arguments here from another file?. Thank you very much for your help. ===================== 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 Simon Levin
for question 2.
SORT CASES BY ID (D). STRING xlist1 (A255). COMPUTE xlist1 = LAG(xlist,2). ** needed to transform data. EXECUTE. For question 3: Are you trying to run multiple aggregates with different variable lists, with the variable list dependent on a variable in the file? If so, the macro you defined works (if the file name is correct). I edited the path to c:\aggtest.sav and it worked as written, once I edited the path to match my computer. You can use WRITE to create a syntax file with the macro call, then use INSERT to run the created file after defining the macro. This seems to work: **test list data not saved. DATA LIST /iD (F1) Pos (F3) X 5-6(A). BEGIN DATA 0 1 1 1 X1 2 1 X2 3 0 X3 END DATA. STRING XList (A255). COMPUTE XList="". LOOP #J=1 TO iD. IF iD=#J XList=LTRIM(CONCAT(RTRIM(LTRIM(LAG(XList))), ' ',RTRIM(LTRIM (X)))). END LOOP IF (Pos=0). LIST. *** move the final xlist entry to pos = 0. STRING XLIST1 (a255). SORT CASES BY id (D). COMPUTE xlist1 = lag(xlist,2). EXE. ** alternate way to identify last xlist. ** it assumes all the pos = 1 entries increase consecutively, ** and the complete list is the one you want. AGGR OUTFILE = * /break = pos /xlist_use = max(xlist). do if pos = 1. write outfile = 'c:\xlsyntax.sps' /'agglist (' xlist_use / ' ).' . end if. exe. ** test data to be aggregated. DATA LIST LIST/BreakX(F1) X1(F1) X2(F1) X3(F1). BEGIN DATA 1 1 2 1 1 1 0 0 2 1 0 1 2 0 2 2 END DATA. ** your macro. DEFINE aggList (!POSITIONAL !enclose( '(' , ')' )). AGGREGATE /OUTFILE = 'c:\aggTEST.sav' /BREAK = BreakX /!1 = sum (!1). !ENDDEFINE. set mprint = yes. *** call the macro from an inserted file. insert file = 'c:\xlsyntax.sps' . the write file doesn't behave as I expect but the resulting aggregated file appears correct. --jim -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Simon Levin Sent: Monday, November 12, 2007 12:26 PM To: [hidden email] Subject: 3 Short Questions con't... Hi all! I need help with 2 questions. Thank you Richard Ristow and ViAnn Beadle. The loop problem is solved, thank you. Let me clarify the other two questions. The example below are simplified examples of very large files. In the first file (TestList.sav) forms list of names of variables (as a string XList when iD=2) that will become arguments for the AGGREGATE specifications for another file (TestX.sav). DATA LIST /iD (F1) Pos (F3) X 5-6(A). BEGIN DATA 0 1 1 1 X1 2 1 X2 3 0 X3 END DATA. STRING XList (A255). COMPUTE XList="". LOOP #J=1 TO iD. IF iD=#J XList=LTRIM(CONCAT(RTRIM(LTRIM(LAG(XList))), ' ',RTRIM(LTRIM (X)))). END LOOP IF (Pos=0). LIST. SAVE OUTFILE='c:\SPSS\TestList.sav'. Question 1: How can I copy the value of Xlist at iD = 2 to Xlist at iD = 0? For example the following doesn't work for strings: CREATE XList1 = LEAD(XList, 2). Question 2: The 2nd file (TestX.sav) contains the variables to be aggregated. I need to assign to the AGGREGATE the list of variables for the TestX.sav file, as values of XList variable, when iD =2 (calculated in the TestList.sav file). DATA LIST LIST/BreakX(F1) X1(F1) X2(F1) X3(F1). BEGIN DATA 1 1 2 1 1 1 0 0 2 1 0 1 2 0 2 2 END DATA. LIST. SAVE OUTFILE='c:\SPSS\TestX.sav'. AGGREGATE /OUTFILE = 'c:\SPSS\aggTestX.sav' /BREAK = BreakX /X1 X2 = sum (X1 X2). /*<---------- How to pass the arguments here from another file?. We can also use DEFINE, but there is the same problem. DEFINE aggList (!POSITIONAL !enclose( '(' , ')' )). AGGREGATE /OUTFILE = 'c:\SPSS\aggTEST.sav' /BREAK = BreakX /!1 = sum (!1). !ENDDEFINE. aggList(X1 X2). /*<---------- How to pass the arguments here from another file?. Thank you very much for your help. ===================== 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 |
