looping, split file and saving

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

Re: looping, split file and saving

xenia
Many thanks, this is extremely useful, I run it as is because I didn't want to pull all my hair out
It works, however there are a few more points below , I'm sorry if it seems trivial/easy to you but I'm not familiar with macros, just starting to learn:
 - if I write !DO !codeval=2 !TO !max, i.e. if my list starts from 2, then shouldn't a_code start from 2 as well?
When I look in the datafile, a_code starts from 1, so if I have IDs 2-4, it goes from 1 to 3.
 - If I run it 3 times, I get e.g. PRED_1, PRED_2, PRED_3 in different columns as mentioned in a previous post, and then in the end I get everything in one column, which is what I want. I guess there is no way to not get the intermediate PRED_1, PRED_2, PRED_3?
- SPLIT FILE BY code automatically gives me the ID/code displayed at the start of each iteration and as a title in the graph. Is there a way to do that here, i.e. have "code" displayed at the start of the regression and as a title in the graph, or simply before the start of the graph procedure?

Thanks again
Reply | Threaded
Open this post in threaded view
|

Re: looping, split file and saving

David Marso
Administrator
Please post the exact code you are running.
--

xenia wrote
Many thanks, this is extremely useful, I run it as is because I didn't want to pull all my hair out
It works, however there are a few more points below , I'm sorry if it seems trivial/easy to you but I'm not familiar with macros, just starting to learn:
 - if I write !DO !codeval=2 !TO !max, i.e. if my list starts from 2, then shouldn't a_code start from 2 as well?
When I look in the datafile, a_code starts from 1, so if I have IDs 2-4, it goes from 1 to 3.
 - If I run it 3 times, I get e.g. PRED_1, PRED_2, PRED_3 in different columns as mentioned in a previous post, and then in the end I get everything in one column, which is what I want. I guess there is no way to not get the intermediate PRED_1, PRED_2, PRED_3?
- SPLIT FILE BY code automatically gives me the ID/code displayed at the start of each iteration and as a title in the graph. Is there a way to do that here, i.e. have "code" displayed at the start of the regression and as a title in the graph, or simply before the start of the graph procedure?

Thanks again
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: looping, split file and saving

xenia

DEFINE loopit (var !TOKENS(1) /max !TOKENS(1)) .
!DO !codeval=2 !TO !max .
COMPUTE FILT=(!var EQ !codeval ).
FILTER BY FILT.

IGRAPH
  /VIEWNAME='Scatterplot'
  /X1=VAR(days) TYPE=SCALE
  /Y=VAR(Fe) TYPE=SCALE
  /COORDINATE=VERTICAL
  /FITLINE METHOD=REGRESSION LINEAR LINE=TOTAL SPIKE=OFF
  /CHARTLOOK='NONE'
  /SCATTER COINCIDENT=NONE
  /POINTLABEL= VAR(sampleno) all.

REGRESSION
  /MISSING LISTWISE
  /CRITERIA=PIN(.05) POUT(.10)
  /NOORIGIN
  /DEPENDENT Fe
  /METHOD=ENTER days
  /SAVE PRED ZPRED ADJPRED SEPRED COOK LEVER RESID ZRESID SRESID DRESID SDRESID
  /RESIDUALS HISTOGRAM(ZRESID) ID(sampleno).

!DOEND
FILTER OFF.
SPLIT FILE BY a_code .
PRESERVE.
SET RESULTS OFF ERRORS OFF.

REGRESSION
  /MISSING LISTWISE
  /CRITERIA=PIN(.05) POUT(.10)
  /NOORIGIN
  /DEPENDENT Fe
  /METHOD=ENTER days
  /SAVE PRED ZPRED ADJPRED SEPRED COOK LEVER RESID ZRESID SRESID DRESID SDRESID
  /RESIDUALS HISTOGRAM(ZRESID) ID(sampleno).
  /SAVE .

RESTORE.
SPLIT FILE OFF.
!ENDDEFINE.

AUTORECODE code / INTO a_code .
SORT CASES BY a_code .
LOOPIT var = a_code max=4.
Reply | Threaded
Open this post in threaded view
|

Re: looping, split file and saving

David Marso
Administrator
In reply to this post by David Marso
-Since you have autorecoded the variable (to produce sequential values) the loop should begin with 1.
-Remove the /SAVE from the first regression.
-See PRINT command.

PRINT / a_code .
IGRAPH ...
PRINT /a_code.
REGRESSION...



David Marso wrote
Please post the exact code you are running.
--

xenia wrote
Many thanks, this is extremely useful, I run it as is because I didn't want to pull all my hair out
It works, however there are a few more points below , I'm sorry if it seems trivial/easy to you but I'm not familiar with macros, just starting to learn:
 - if I write !DO !codeval=2 !TO !max, i.e. if my list starts from 2, then shouldn't a_code start from 2 as well?
When I look in the datafile, a_code starts from 1, so if I have IDs 2-4, it goes from 1 to 3.
 - If I run it 3 times, I get e.g. PRED_1, PRED_2, PRED_3 in different columns as mentioned in a previous post, and then in the end I get everything in one column, which is what I want. I guess there is no way to not get the intermediate PRED_1, PRED_2, PRED_3?
- SPLIT FILE BY code automatically gives me the ID/code displayed at the start of each iteration and as a title in the graph. Is there a way to do that here, i.e. have "code" displayed at the start of the regression and as a title in the graph, or simply before the start of the graph procedure?

Thanks again
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: looping, split file and saving

xenia
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: looping, split file and saving

David Marso
Administrator
OK.  I have a deadline today so am simply going to direct you to
MATCH FILES see FIRST function (to mark first instance of a_code)
and
DO IF ..END IF statements (wrap around the PRINT)
Use PRINT / !var.
since you are passing the varname into the macro and might as well keep it general.  

xenia wrote
ok,
I run this:
DEFINE loopit (var !TOKENS(1) /max !TOKENS(1)) .
!DO !codeval=1 !TO !max.
 COMPUTE FILT=(!var EQ !codeval ).
 FILTER BY FILT.
 
 PRINT / a_code .
 IGRAPH
   /VIEWNAME='Scatterplot'
   /X1=VAR(daysfromlastscreening) TYPE=SCALE
   /Y=VAR(resultAFP ) TYPE=SCALE
   /COORDINATE=VERTICAL
   /FITLINE METHOD=REGRESSION LINEAR LINE=TOTAL SPIKE=OFF
   /CHARTLOOK='NONE'
   /SCATTER COINCIDENT=NONE
   /POINTLABEL= VAR(sampleno) all.


 REGRESSION
   /MISSING LISTWISE
   /CRITERIA=PIN(.05) POUT(.10)
   /NOORIGIN
   /DEPENDENT resultAFP
   /METHOD=ENTER daysfromlastscreening
   /RESIDUALS HISTOGRAM(ZRESID) ID(sampleno).

!DOEND
FILTER OFF.
SPLIT FILE BY a_code .
PRESERVE.
SET RESULTS OFF ERRORS OFF.


 REGRESSION
   /MISSING LISTWISE
   /CRITERIA=PIN(.05) POUT(.10)
   /NOORIGIN
   /DEPENDENT resultAFP
   /METHOD=ENTER daysfromlastscreening
   /SAVE PRED ZPRED ADJPRED SEPRED COOK LEVER RESID ZRESID SRESID DRESID SDRESID
   /RESIDUALS HISTOGRAM(ZRESID) ID(sampleno).
   /SAVE .

RESTORE.
SPLIT FILE OFF.
!ENDDEFINE.

AUTORECODE code / INTO a_code .
SORT CASES BY a_code .
LOOPIT var = a_code max=4.

and before each graph I don't get the current code/ID but a list of all of them, i.e. suppose the IDs start from 1, so I have ids 1, 2,3, 4, it is the 2nd iteration and instead of 2 I get 1,2,3,4. I don't understand why.
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: looping, split file and saving

xenia
In reply to this post by David Marso
ok,
I run this:
DEFINE loopit (var !TOKENS(1) /max !TOKENS(1)) .
!DO !codeval=1 !TO !max.
 COMPUTE FILT=(!var EQ !codeval ).
 FILTER BY FILT.
 
 PRINT / a_code .
 IGRAPH
   /VIEWNAME='Scatterplot'
   /X1=VAR(days) TYPE=SCALE
   /Y=VAR(Fe) TYPE=SCALE
   /COORDINATE=VERTICAL
   /FITLINE METHOD=REGRESSION LINEAR LINE=TOTAL SPIKE=OFF
   /CHARTLOOK='NONE'
   /SCATTER COINCIDENT=NONE
   /POINTLABEL= VAR(sampleno) all.


 REGRESSION
   /MISSING LISTWISE
   /CRITERIA=PIN(.05) POUT(.10)
   /NOORIGIN
   /DEPENDENT Fe
   /METHOD=ENTER days
   /RESIDUALS HISTOGRAM(ZRESID) ID(sampleno).

!DOEND
FILTER OFF.
SPLIT FILE BY a_code .
PRESERVE.
SET RESULTS OFF ERRORS OFF.


 REGRESSION
   /MISSING LISTWISE
   /CRITERIA=PIN(.05) POUT(.10)
   /NOORIGIN
   /DEPENDENT Fe
   /METHOD=ENTER days
   /SAVE PRED ZPRED ADJPRED SEPRED COOK LEVER RESID ZRESID SRESID DRESID SDRESID
   /RESIDUALS HISTOGRAM(ZRESID) ID(sampleno).
   /SAVE .

RESTORE.
SPLIT FILE OFF.
!ENDDEFINE.

AUTORECODE code / INTO a_code .
SORT CASES BY a_code .
LOOPIT var = a_code max=4.

and before each graph I don't get the current code/ID but a list of all of them, i.e. suppose the IDs start from 1, so I have ids 1, 2,3, 4, it is the 2nd iteration and instead of 2 I get 1,2,3,4. I don't understand why.
Reply | Threaded
Open this post in threaded view
|

Re: looping, split file and saving

xenia
In reply to this post by David Marso
thank you, will try that.....
Reply | Threaded
Open this post in threaded view
|

Re: looping, split file and saving

xenia
In reply to this post by David Marso
To summarize, the last problem I had in this task was that I had a series of IDs and corresponding data and wanted procedures performed for each ID, so each iteration deals with one ID at a time. I also wanted the current ID to be displayed at the start of each iteration e.g. before the graph and the regression.
D.Marso suggested the following:

SORT CASES BY ID.
MATCH FILES / FILE * / FIRST=@TOP@ / BY ID.
DO IF @TOP@.
PRINT ID.
END IF.

so, because I want the current ID to be displayed at each iteration, I modified it a bit and below is the whole code:


DEFINE loopit (var !TOKENS(1) /max !TOKENS(1))
!DO !codeval=1 !TO !max
 COMPUTE FILT=(!var EQ !codeval ).
 FILTER BY FILT.

  SORT CASES BY !var.
  MATCH FILES / FILE * / FIRST=@TOP@ / BY !var.
  DO IF FILT=1.
  DO IF @TOP@.
    PRINT / "code = " !var.    
  END IF.
  END IF.
  SAVE OUTFILE='H:\projects\a.sav'
  /COMPRESSED.

  IGRAPH
   /VIEWNAME='Scatterplot'
   /X1=VAR(days) TYPE=SCALE
   /Y=VAR(Fe ) TYPE=SCALE
   /COORDINATE=VERTICAL
   /FITLINE METHOD=REGRESSION LINEAR LINE=TOTAL SPIKE=OFF
   /CHARTLOOK='NONE'
   /SCATTER COINCIDENT=NONE
   /POINTLABEL= VAR(sampleno) all.


 REGRESSION
   /MISSING LISTWISE
   /CRITERIA=PIN(.05) POUT(.10)
   /NOORIGIN
   /DEPENDENT Fe
   /METHOD=ENTER days
   /RESIDUALS HISTOGRAM(ZRESID) ID(sampleno).

!DOEND
FILTER OFF.
SPLIT FILE BY a_code.
PRESERVE.
SET RESULTS OFF ERRORS OFF.

 REGRESSION
   /MISSING LISTWISE
   /CRITERIA=PIN(.05) POUT(.10)
   /NOORIGIN
   /DEPENDENT Fe
   /METHOD=ENTER days
   /SAVE PRED ZPRED ADJPRED SEPRED COOK LEVER RESID ZRESID SRESID DRESID SDRESID
   /RESIDUALS HISTOGRAM(ZRESID) ID(sampleno).
 /SAVE .

RESTORE.
SPLIT FILE OFF.
!ENDDEFINE.

AUTORECODE code / INTO a_code.
SORT CASES BY a_code.
LOOPIT var = a_code max=1000.


Thank you to everyone who has helped with this. This might be very easy for the experienced programmers, but it is difficult for people who are now trying to learn a bit more than the standard syntax, like me for example. An example is  FIRST=@TOP@, even if one reads SPSS help he/she might not be aware that "TOP" exists and that they can use it with that notation to do what they want. It takes a lot of searching around and reading.
Reply | Threaded
Open this post in threaded view
|

Re: looping, split file and saving

David Marso
Administrator
As a final comment.
Put the SORT and MATCH outside of the !DO .
Same goes with the SAVE (optional).
Don't need to sort and tag the data multiple times.
Finally @TOP@ is just another variable name.  
FIRST is the important concept here.
I will commonly use @ around new variables to mark them as having some special status.
Also if you already had a variable named TOP the match command would result in an error.
FWIW:
The following:
DO IF FILT=1.
  DO IF @TOP@.
    PRINT / "code = " !var.    
  END IF.
  END IF.

can be written as:

DO IF (FILT AND @TOP@).
PRINT / "code = " !var.    
END IF.

HTH, DMM

xenia wrote
To summarize, the last problem I had in this task was that I had a series of IDs and corresponding data and wanted procedures performed for each ID, so each iteration deals with one ID at a time. I also wanted the current ID to be displayed at the start of each iteration e.g. before the graph and the regression.
D.Marso suggested the following:

SORT CASES BY ID.
MATCH FILES / FILE * / FIRST=@TOP@ / BY ID.
DO IF @TOP@.
PRINT ID.
END IF.

so, because I want the current ID to be displayed at each iteration, I modified it a bit and below is the whole code:


DEFINE loopit (var !TOKENS(1) /max !TOKENS(1))
!DO !codeval=1 !TO !max
 COMPUTE FILT=(!var EQ !codeval ).
 FILTER BY FILT.

  SORT CASES BY !var.
  MATCH FILES / FILE * / FIRST=@TOP@ / BY !var.
  DO IF FILT=1.
  DO IF @TOP@.
    PRINT / "code = " !var.    
  END IF.
  END IF.
  SAVE OUTFILE='H:\projects\a.sav'
  /COMPRESSED.

  IGRAPH
   /VIEWNAME='Scatterplot'
   /X1=VAR(days) TYPE=SCALE
   /Y=VAR(Fe ) TYPE=SCALE
   /COORDINATE=VERTICAL
   /FITLINE METHOD=REGRESSION LINEAR LINE=TOTAL SPIKE=OFF
   /CHARTLOOK='NONE'
   /SCATTER COINCIDENT=NONE
   /POINTLABEL= VAR(sampleno) all.


 REGRESSION
   /MISSING LISTWISE
   /CRITERIA=PIN(.05) POUT(.10)
   /NOORIGIN
   /DEPENDENT Fe
   /METHOD=ENTER days
   /RESIDUALS HISTOGRAM(ZRESID) ID(sampleno).

!DOEND
FILTER OFF.
SPLIT FILE BY a_code.
PRESERVE.
SET RESULTS OFF ERRORS OFF.

 REGRESSION
   /MISSING LISTWISE
   /CRITERIA=PIN(.05) POUT(.10)
   /NOORIGIN
   /DEPENDENT Fe
   /METHOD=ENTER days
   /SAVE PRED ZPRED ADJPRED SEPRED COOK LEVER RESID ZRESID SRESID DRESID SDRESID
   /RESIDUALS HISTOGRAM(ZRESID) ID(sampleno).
 /SAVE .

RESTORE.
SPLIT FILE OFF.
!ENDDEFINE.

AUTORECODE code / INTO a_code.
SORT CASES BY a_code.
LOOPIT var = a_code max=1000.


Thank you to everyone who has helped with this. This might be very easy for the experienced programmers, but it is difficult for people who are now trying to learn a bit more than the standard syntax, like me for example. An example is  FIRST=@TOP@, even if one reads SPSS help he/she might not be aware that "TOP" exists and that they can use it with that notation to do what they want. It takes a lot of searching around and reading.
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: looping, split file and saving

xenia
In reply to this post by xenia
It appears I can't close this post, as I have a further query.
In the same context that I have described, let's say I have IDs 1,2,3,4 and I also have a string variable with respective values "ID 1", "ID 2", "ID 3", "ID 4". For the iteration performed on ID 1 and the respective graph, I would like the title of the graph to display "ID 1",  etc. Is there a way to read the value of the string variable at each iteration and set it as the title of the graph?

Thank you all
Reply | Threaded
Open this post in threaded view
|

Automatic reply: looping, split file and saving

Lorin Drake
Thank you for your message. Our offices are closed on November 22 and 23 in observance of the U.S. Thanksgiving holiday. 
I will return on Monday, November 26 and will reply to your email then. 
Reply | Threaded
Open this post in threaded view
|

Re: looping, split file and saving

Jon K Peck
In reply to this post by xenia
This would have all been so much easier if you had taken my suggestion of doing this with the extension commands I suggested.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        xenia <[hidden email]>
To:        [hidden email],
Date:        11/21/2012 01:46 PM
Subject:        Re: [SPSSX-L] looping, split file and saving
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




It appears I can't close this post, as I have a further query.
In the same context that I have described, let's say I have IDs 1,2,3,4 and
I also have a string variable with respective values "ID 1", "ID 2", "ID 3",
"ID 4". For the iteration performed on ID 1 and the respective graph, I
would like the title of the graph to display "ID 1",  etc. Is there a way to
read the value of the string variable at each iteration and set it as the
title of the graph?

Thank you all



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/looping-split-file-and-saving-tp5715711p5716398.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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


Reply | Threaded
Open this post in threaded view
|

Re: looping, split file and saving

David Marso
Administrator
In reply to this post by xenia
Please look at the documentation for the PRINT command!
You have been served up all the pieces.  
At some point you must reflect upon their meaning.
I understand you are new at SPSS.  
Perhaps even a better reason to study the manual.
--
xenia wrote
It appears I can't close this post, as I have a further query.
In the same context that I have described, let's say I have IDs 1,2,3,4 and I also have a string variable with respective values "ID 1", "ID 2", "ID 3", "ID 4". For the iteration performed on ID 1 and the respective graph, I would like the title of the graph to display "ID 1",  etc. Is there a way to read the value of the string variable at each iteration and set it as the title of the graph?

Thank you all
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: looping, split file and saving

xenia
In reply to this post by Jon K Peck
I guess, but I can only try at home and have been too tired when I return from work. At work I have put in a request with the IT, because I can download but I cannot install, don't have rights. I haven't excluded your solution, because I want to have a go and try python, so I'm trying out all the suggested solutions. It's the next thing to do, but I have to either find time at home or wait for IT to install it for me. I did get the impression by what you wrote that it should be easier with python.

On 21 November 2012 23:08, Jon K Peck <[hidden email]> wrote:
This would have all been so much easier if you had taken my suggestion of doing this with the extension commands I suggested.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: <a href="tel:720-342-5621" target="_blank" value="+17203425621">720-342-5621




From:        xenia <[hidden email]>
To:        [hidden email],
Date:        11/21/2012 01:46 PM
Subject:        Re: [SPSSX-L] looping, split file and saving
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




It appears I can't close this post, as I have a further query.
In the same context that I have described, let's say I have IDs 1,2,3,4 and
I also have a string variable with respective values "ID 1", "ID 2", "ID 3",
"ID 4". For the iteration performed on ID 1 and the respective graph, I
would like the title of the graph to display "ID 1",  etc. Is there a way to
read the value of the string variable at each iteration and set it as the
title of the graph?

Thank you all



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/looping-split-file-and-saving-tp5715711p5716398.html

Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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



Reply | Threaded
Open this post in threaded view
|

Re: looping, split file and saving

xenia
In reply to this post by David Marso
I want "ID....." to be displayed as the title of the graph, not before the graph. I used IGRAPH,  in the command syntax reference I don't see PRINT used within IGRAPH.  IGRAPH takes a TITLE which must be a string. So I cannot pass the !var item I used in the preceding macro, which is what I tried to do. I do look at the syntax and try to do it myself before posting, so if I post it means I couldn't do it. I'm trying to automate this task for example, so that I don't have to go into every graph and change it manually, but it seems even doing that would be quicker than reading references and examples for hours on end just to be able to put a title in. The title is a small detail compared to everything else I have to do, I would like to automate it but I seem to be spending more time in finding out how to change titles and fonts than running the actual methods I need to run. What can I say, not everybody is as clever as you are.














 
123