Vector\Loop Question

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Vector\Loop Question

SUBSCRIBE SPSSX-JohnF
I have a source file with 10 years of data in it and I've identified 5 subpopulations in the file.  The code below generates a percent change year to year for the subpopulation(s), however I have 5 sets of the code below, one for each sub population, clearly not the most efficient approach but it works for now.  What I'd like to do, since there are 5 sets of code recognizing the source file may not always have 10 years of data in it and the loop 1 to 9 will change, I am trying to figure a central location to change the loop count accordingly and have the change picked up in all 5 sets of code.  I tried a simple macro representing the loop construction which didn't work.....any ideas would be much appreciated.


numeric trendNC (f4.1).
vector A=EntryTrend/B=trendNC.
loop #C=1 to 9.
compute B(#C)=((A(#C+1)-A(#C))/A(#C))*100.
end loop.
exe.

Public Thanks to Mr. Peck and Mr. Marso for assistance with prior coding issue.

=====================
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
|  
Report Content as Inappropriate

Re: Vector\Loop Question

SUBSCRIBE SPSSX-JohnF
I figured out a solution...still learning....Thanks All.

=====================
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
|  
Report Content as Inappropriate

Re: Vector\Loop Question

David Marso
Administrator
Maybe you should post the solution?  Probably ways to dehackify it?

SUBSCRIBE SPSSX-JohnF wrote
I figured out a solution...still learning....Thanks All.

=====================
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
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
|  
Report Content as Inappropriate

Re: Vector\Loop Question

David Marso
Administrator
In reply to this post by SUBSCRIBE SPSSX-JohnF
Most basic obvious problem here is the VECTOR is NOT declared correctly.
See FM for deets.
You also don't specify whether the data are in wide or long format.
Clearly specifying the actual data structure and the required end product is usually best.  How are these subpopulations  denoted in the file?
Are these 5 sets of aggregate values stacked in the data file?
Seriously John, don't depend upon our InterneTelepathy and ESP_SS.
Assuming that the data are such.

SubPop Time Value
1 1
1 2
1 3
1 4
1 5
.
.
.
1  10
2  1
2  2
2  ..
2  7
3
.....
ETC.

SPLIT FILE BY SubPop.
CREATE Next=LEAD(Value,1).
COMPUTE Trend=(Next-Value)/Value *100.



SUBSCRIBE SPSSX-JohnF wrote
I have a source file with 10 years of data in it and I've identified 5 subpopulations in the file.  The code below generates a percent change year to year for the subpopulation(s), however I have 5 sets of the code below, one for each sub population, clearly not the most efficient approach but it works for now.  What I'd like to do, since there are 5 sets of code recognizing the source file may not always have 10 years of data in it and the loop 1 to 9 will change, I am trying to figure a central location to change the loop count accordingly and have the change picked up in all 5 sets of code.  I tried a simple macro representing the loop construction which didn't work.....any ideas would be much appreciated.


numeric trendNC (f4.1).
vector A=EntryTrend/B=trendNC.
loop #C=1 to 9.
compute B(#C)=((A(#C+1)-A(#C))/A(#C))*100.
end loop.
exe.

Public Thanks to Mr. Peck and Mr. Marso for assistance with prior coding issue.

=====================
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
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
|  
Report Content as Inappropriate

Re: Vector\Loop Question

SUBSCRIBE SPSSX-JohnF
In reply to this post by SUBSCRIBE SPSSX-JohnF
Thanks for the response.  It is a wide file and I managed to solve the problem I had relative to the changing number of years related to the macro which calculates the percent changes from year to year, using the "ELoop" macro found below, which I realize isn't efficient,.  

Now I have another problem which I can't seem to figure out...any help would be greatly appreciated.  

The macro below represents one sub-pop (there are 4 others), however the years can change and I don't want to change every occurrence of 2006, 2007 and 2015 in these macros.  I thought something like this might work using a concat function....

define sYR () 2006
!enddefine.

then concat it with, for example Entered_sum.

I can't figure out to provide one central location to change the begin and end years and have each of the macros below pick up the changes.  The source file has a fiscal year in it, therefore when the source file is re-structured, by default the fiscal years are placed on the variable names, i.e.,  entered_sum.2006, entered_sum.2007 and so on.

define EntryTrend () Entered_sum.2006.00 to Entered_sum.2015.00.
!enddefine.

define trendNC () EntryChange.07 to EntryChange.15
!enddefine.
.

define ELoop () 9
!enddefine.

********  END USER INPUT ********


numeric trendNC (f4.1).
vector A=EntryTrend/B=trendNC.
loop #C=1 to ELoop.
compute B(#C)=((A(#C+1)-A(#C))/A(#C))*100.
end loop.
exe.

=====================
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
|  
Report Content as Inappropriate

Re: Vector\Loop Question

David Marso
Administrator
"source file has a fiscal year in it, therefore when the source file is re-structured, by default the fiscal years are placed on the variable names, i.e.,  entered_sum.2006, entered_sum.2007 and so on. "

From this I infer the data were in LONG format to begin with.
Your using CASESTOVARS effectively screwed the pooch.
Back up a bit, study the code I posted using CREATE with SPLIT FILE.
You are making something which is very simple into a novella.

BTW:  When you define Macros you should prefix them with !
(eg !ELoop) so you don't step on your tender bits and make a big mess.
If this makes no sense to you then consider that ELoop, sYR, EntryTrend and  trendNC  are all valid variable names whereas !ELoop, !sYR, !EntryTrend and !trendNC  are not.

FURTHERMORE you will make your life a living hell by having these sitting around when you REALLY should have a single macro which takes parameters.  If this is mysterious to you then you need to RTFM and read my postings in this list.  I have posted several hundred examples over the past 20 years.

SUBSCRIBE SPSSX-JohnF wrote
Thanks for the response.  It is a wide file and I managed to solve the problem I had relative to the changing number of years related to the macro which calculates the percent changes from year to year, using the "ELoop" macro found below, which I realize isn't efficient,.  

Now I have another problem which I can't seem to figure out...any help would be greatly appreciated.  

The macro below represents one sub-pop (there are 4 others), however the years can change and I don't want to change every occurrence of 2006, 2007 and 2015 in these macros.  I thought something like this might work using a concat function....

define sYR () 2006
!enddefine.

then concat it with, for example Entered_sum.

I can't figure out to provide one central location to change the begin and end years and have each of the macros below pick up the changes.  The source file has a fiscal year in it, therefore when the source file is re-structured, by default the fiscal years are placed on the variable names, i.e.,  entered_sum.2006, entered_sum.2007 and so on.

define EntryTrend () Entered_sum.2006.00 to Entered_sum.2015.00.
!enddefine.

define trendNC () EntryChange.07 to EntryChange.15
!enddefine.
.

define ELoop () 9
!enddefine.

********  END USER INPUT ********


numeric trendNC (f4.1).
vector A=EntryTrend/B=trendNC.
loop #C=1 to ELoop.
compute B(#C)=((A(#C+1)-A(#C))/A(#C))*100.
end loop.
exe.

=====================
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
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?"
Loading...