|
Dear friends,
I have a question related with programming in SPSS (with the SINTAX). I want to process a file of data. More precisely, I want to process it row by row -I mean, I want to read one row of the data file, and to do operations with the values (the fields), and then to write the result in another file (or in the same). Then, I want to read another row, and do the same, and so on. I need some auxiliar "variables" to be maintained within the loop (I mean, when processing one file of the rows, maybe I update one variable, and then I read its value when I am processing another row). So, what I need: - A kind of loop in order to process a data file, row by row. - Using variables (in the computer programming sense, not the statistical one). "Global" variables, if you want. Can anyone help me??? Thank you for you help! -- Vicent |
|
Dear Vicent,
I think, there is no direct possibility to process the case data individually with SPSS-Syntax. Depending on transformations you want to do, flipping the data and processing the variables (=cases) may be on alternative (naturally flipping back the data after the transformations done). When it doesn't work, there is straight forward flexibel facilities to perform row by row computations in programmability extension (python). Regards Vladimir Vicent Giner Bosch <[hidden email]> Gesendet von: "SPSSX(r) Discussion" <[hidden email]> 08.06.2007 12:48 Bitte antworten an Vicent Giner Bosch <[hidden email]> An [hidden email] Kopie Thema Programming with SPSS Dear friends, I have a question related with programming in SPSS (with the SINTAX). I want to process a file of data. More precisely, I want to process it row by row -I mean, I want to read one row of the data file, and to do operations with the values (the fields), and then to write the result in another file (or in the same). Then, I want to read another row, and do the same, and so on. I need some auxiliar "variables" to be maintained within the loop (I mean, when processing one file of the rows, maybe I update one variable, and then I read its value when I am processing another row). So, what I need: - A kind of loop in order to process a data file, row by row. - Using variables (in the computer programming sense, not the statistical one). "Global" variables, if you want. Can anyone help me??? Thank you for you help! -- Vicent This email and any attachments may contain confidential or privileged information. Please note that unauthorized copying, disclosure or distribution of the material in this email is not permitted. GfK Aktiengesellschaft, Nuremberg, Germany, commercial register Nuremberg HRB 9398; Management Board: Professor Dr. Klaus L. Wübbenhorst (CEO), Christian Weller von Ahlefeld (CFO), Petra Heinlein, Dr. Gérard Hermet, Wilhelm R. Wessels; Chairman of the Supervisory Board: Hajo Riesenbeck |
|
The OP says that he wants to loop through cases which is exactly what SPSS
does. No external loop is required to drive the transformation. However, the description is too vague for anybody to provide a solution. Let's start with what is the goal of this exercise along with a description of what data look like now and what data look like after being transformed. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Vladimir Manewitsch Sent: Friday, June 08, 2007 8:38 AM To: [hidden email] Subject: Antwort: Programming with SPSS Dear Vicent, I think, there is no direct possibility to process the case data individually with SPSS-Syntax. Depending on transformations you want to do, flipping the data and processing the variables (=cases) may be on alternative (naturally flipping back the data after the transformations done). When it doesn't work, there is straight forward flexibel facilities to perform row by row computations in programmability extension (python). Regards Vladimir Vicent Giner Bosch <[hidden email]> Gesendet von: "SPSSX(r) Discussion" <[hidden email]> 08.06.2007 12:48 Bitte antworten an Vicent Giner Bosch <[hidden email]> An [hidden email] Kopie Thema Programming with SPSS Dear friends, I have a question related with programming in SPSS (with the SINTAX). I want to process a file of data. More precisely, I want to process it row by row -I mean, I want to read one row of the data file, and to do operations with the values (the fields), and then to write the result in another file (or in the same). Then, I want to read another row, and do the same, and so on. I need some auxiliar "variables" to be maintained within the loop (I mean, when processing one file of the rows, maybe I update one variable, and then I read its value when I am processing another row). So, what I need: - A kind of loop in order to process a data file, row by row. - Using variables (in the computer programming sense, not the statistical one). "Global" variables, if you want. Can anyone help me??? Thank you for you help! -- Vicent This email and any attachments may contain confidential or privileged information. Please note that unauthorized copying, disclosure or distribution of the material in this email is not permitted. GfK Aktiengesellschaft, Nuremberg, Germany, commercial register Nuremberg HRB 9398; Management Board: Professor Dr. Klaus L. Wübbenhorst (CEO), Christian Weller von Ahlefeld (CFO), Petra Heinlein, Dr. Gérard Hermet, Wilhelm R. Wessels; Chairman of the Supervisory Board: Hajo Riesenbeck |
|
In reply to this post by Vicent Giner-Bosch
Vicent, your description is a bit vague. There are many ways of
doing things like the ones you describe, depending on your particular situation and purpose. SPSS always proceeds row by row when doing transformation procedures (or when considering cases for a statistical procedure). No need for a specific programming trick to do so. What you call auxiliary "variables" in the computer sense would actually be "constants", unless they are different from one case (row) to another, and they may be simply mentioned in the syntax without further fuss. If they are "counters" that increase or decrease as more cases (rows) are processed, this can be implemented through a loop. Computing new variables based on the old is easy: use the COMPUTE command. For example: COMPUTE NEWVAR=SQRT(OLDVAR) would create a variable called NEWVAR that (for each row) equals the square root of the value of another variable called OLDVAR. Scratch variables (that vary across rows) can be created in a variety of ways, if necessary. You can also create actual hard variables and then delete them at the end of the procedure. The new variables can created in many ways; among these ways, they can be imported from a second file which is merged with the first one. The results of transformations, i.e. the value of new variables, are first written as new variables in the same file. After that, you can create a new file with the new values for the same rows (or part of them). This is done in SPSS in several possible ways, mostly through the SAVE or XSAVE commands. You can also create an aggregate file with group summaries, for instance with the mean or sum of the variables for each group of rows defined by some other variable. This aggregate file will have, of course, fewer rows than the original since each row now represents a group of original rows. SPSS does this through the AGGREGATE command. Look at the basics of syntax in the syntax reference manual (see Help in the menu, or look for it in the SPSS installation disk), and all this will come clear. Hector -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Vicent Giner Bosch Sent: 08 June 2007 07:44 To: [hidden email] Subject: Programming with SPSS Dear friends, I have a question related with programming in SPSS (with the SINTAX). I want to process a file of data. More precisely, I want to process it row by row -I mean, I want to read one row of the data file, and to do operations with the values (the fields), and then to write the result in another file (or in the same). Then, I want to read another row, and do the same, and so on. I need some auxiliar "variables" to be maintained within the loop (I mean, when processing one file of the rows, maybe I update one variable, and then I read its value when I am processing another row). So, what I need: - A kind of loop in order to process a data file, row by row. - Using variables (in the computer programming sense, not the statistical one). "Global" variables, if you want. Can anyone help me??? Thank you for you help! -- Vicent |
|
In reply to this post by Vladimir Manewitsch
From Vicent's original message I did not gather that he wanted to
work on variables rather than cases. If that is the situation, of course, he should flip the file with CASETOVARS. Hector -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Vladimir Manewitsch Sent: 08 June 2007 11:38 To: [hidden email] Subject: Antwort: Programming with SPSS Dear Vicent, I think, there is no direct possibility to process the case data individually with SPSS-Syntax. Depending on transformations you want to do, flipping the data and processing the variables (=cases) may be on alternative (naturally flipping back the data after the transformations done). When it doesn't work, there is straight forward flexibel facilities to perform row by row computations in programmability extension (python). Regards Vladimir Vicent Giner Bosch <[hidden email]> Gesendet von: "SPSSX(r) Discussion" <[hidden email]> 08.06.2007 12:48 Bitte antworten an Vicent Giner Bosch <[hidden email]> An [hidden email] Kopie Thema Programming with SPSS Dear friends, I have a question related with programming in SPSS (with the SINTAX). I want to process a file of data. More precisely, I want to process it row by row -I mean, I want to read one row of the data file, and to do operations with the values (the fields), and then to write the result in another file (or in the same). Then, I want to read another row, and do the same, and so on. I need some auxiliar "variables" to be maintained within the loop (I mean, when processing one file of the rows, maybe I update one variable, and then I read its value when I am processing another row). So, what I need: - A kind of loop in order to process a data file, row by row. - Using variables (in the computer programming sense, not the statistical one). "Global" variables, if you want. Can anyone help me??? Thank you for you help! -- Vicent This email and any attachments may contain confidential or privileged information. Please note that unauthorized copying, disclosure or distribution of the material in this email is not permitted. GfK Aktiengesellschaft, Nuremberg, Germany, commercial register Nuremberg HRB 9398; Management Board: Professor Dr. Klaus L. Wübbenhorst (CEO), Christian Weller von Ahlefeld (CFO), Petra Heinlein, Dr. Gérard Hermet, Wilhelm R. Wessels; Chairman of the Supervisory Board: Hajo Riesenbeck |
|
In reply to this post by Vicent Giner-Bosch
At 06:43 AM 6/8/2007, Vicent Giner Bosch wrote:
>I want to process a file of data. More precisely, I want to process it >row by row -I mean, I want to read one row of the data file, and to do >operations with the values (the fields), and then to write the result >in another file (or in the same). Then, I want to read another row, >and do the same, and so on. That is THE most natural thing to do in SPSS. If you write a transformation program that follows a GET FILE, DATA LIST, etc., the incoming file is read record by record and the transformation code executed for each record. You don't see the "write the result in another file", but it's there. It becomes the file known as the SPSS 'working file' or 'active dataset'. You can save it as an SPSS file with 'SAVE OUTFILE='; or, there are other ways, to make it a new dataset (SPSS 14 and 15), or an ASCII file, etc. >I need some auxiliary "variables" to be maintained within the loop (I >mean, when processing one file of the rows, maybe I update one >variable, and then I read its value when I am processing another row). There are various ways to do that, too: . LAG(variable) is the value of variable from the preceding case (row). . If you specify LEAVE for a variable *that is created in the transformation program*, that variable carries over its value from the preceding case, instead of being initialized to system-missing (numbers) or blank (strings) at the start of each case (row). . Nearest to what you want, maybe, are scratch variables. Their names begin with '#'. They always their values between cases, until their values are changed explicitly. They are not saved in the final file. Does this get you closer? Ask more, if you need to. -Good luck, Richard |
| Free forum by Nabble | Edit this page |
