Loops

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

Loops

Tiffany Swinimer
Hi,

I've just signed up for this list and I'm not even sure if it's still running since the "last updated date" on the bottom of the page was 2002.
My problem is one that I feel should be simple to solve, but not having much spss syntax background, I'm not sure how to make it work.
I have a list of accounts, and various prices associated with them. In java, if I wanted to apply something to each group of accounts, I would use a loop.
(for i <=n
         total = cost[i] + total
 )
or something along those lines. Essentially, I am trying to get the program to put the total of the whole account on every line for that account.
I have tried the casestovars command, but it is not quite the format I am looking for.
Any help would be greatly appreciated.

Thanks a lot

Tiffany
Reply | Threaded
Open this post in threaded view
|

Re: Loops

Richard Ristow
At 01:33 PM 7/5/2007, Tiffany Swinimer wrote:

>I've just signed up for this list

Well, welcome, and we're glad to have you.

>I'm not even sure if it's still running since the "last updated date"
>on the bottom of the page was 2002.

Well, I think we're still running. Yours is, indeed, only the 7th
posting today, but it *is* the day after a holiday.

>I have a list of accounts, and various prices associated with them.

OK, to start: It looks like an account has a number of SPSS records
('cases'); every record has a price; and

>I am trying to get the program to put the total of the whole account
>on every line for that account.

You have to have a variable (or a set of variables) that uniquely
identify the account; I'll call it 'Account#'. To add all the values of
Price for the account, and put the total in every record for that
account, then (not tested),

AGGREGATE OUTFILE=* MODE=ADDVARIABLES
    /BREAK=Account#
    /TotPrice 'Total of all prices for account'=SUM(Price).

If I've misunderstood, or you have an early SPSS version without
'MODE=ADDVARIABLES', or anything else doesn't work, post again.

-Welcome and good luck,
  Richard Ristow
Reply | Threaded
Open this post in threaded view
|

Re: Loops

Maguin, Eugene
In reply to this post by Tiffany Swinimer
Tiffany,

I not quite sure what you want from your description but is sounds like this
example might be correct.

Rec price total
1    5.05  5.05
2    1.23  6.28
3    3.22  9.50
4    4.00 13.50
5    9.95 15.00

So that for each record, total is the value on the previous record plus the
value of price on the current record. Could this be correct?

A really big problem is whether a file contains one account or multiple
accounts. I'll assume the former because it is easier.

Do if ($casenum eq 1).
+  compute total=price.
Else.
+  compute total=price+lag(total).
End if.
Reply | Threaded
Open this post in threaded view
|

Re: Loops

Daniel E WILLIAMS
In reply to this post by Tiffany Swinimer
Tiffany, if your data is in the format:

Account Cost1 Cost2 Cost3
A 90 23 23
B 23 12 45
...

Then the command "COMPUTE Total = SUM(Cost1 TO Cost3)" will create:

Account Cost1 Cost2 Cost3 Total
A 90 23 23 136
B 23 12 45 80
...


Dan Williams
Forecasting, Research and Analysis Office
Department of Human Services
State of Oregon, USA
503 947 5354

>>> "Tiffany Swinimer" <[hidden email]> 7/5/2007 10:33:47 AM >>>

Hi,

I've just signed up for this list and I'm not even sure if it's still
running since the "last updated date" on the bottom of the page was
2002.
My problem is one that I feel should be simple to solve, but not having
much spss syntax background, I'm not sure how to make it work.
I have a list of accounts, and various prices associated with them. In
java, if I wanted to apply something to each group of accounts, I would
use a loop.
(for i <=n
         total = cost[i] + total
)
or something along those lines. Essentially, I am trying to get the
program to put the total of the whole account on every line for that
account.
I have tried the casestovars command, but it is not quite the format I
am looking for.
Any help would be greatly appreciated.

Thanks a lot

Tiffany
Reply | Threaded
Open this post in threaded view
|

Re: Loops

ViAnn Beadle
In reply to this post by Tiffany Swinimer
Is your goal to produce some sort of report or do you want data aggregated
for further analysis? SPSS has a number of tabulation and reporting
procedures which can be used to sum some variable x across instances of
another variable. Go to the Help index to find information on procedures
such as REPORT, SUMMARIZE, TABLES, and CTABLES. If you want to aggregate
data for further analysis, look to the AGGREGATE to produce summarized data.

TABLES and CTABLES are not part of base SPSS but provide many options for
creating a customized report.

You'll find that many posters on this list prefer to use SPSS syntax but
don't overlook the dialog boxes from the menus. You'll find the reporting
procedures on the Analysis menu. Sometimes you'll have to write your own
syntax to handle special situations both in desired output and unusual data
structures. From the basic description, this doesn't sound like one of them.

You'll find more direct and helpful responses if you describe your
data--what defines a case (row) of data and what variables are defined for
that case.

Finally, let us know what release of SPSS you are running because solutions
will differ by release.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Tiffany Swinimer
Sent: Thursday, July 05, 2007 11:34 AM
To: [hidden email]
Subject: Loops

Hi,

I've just signed up for this list and I'm not even sure if it's still
running since the "last updated date" on the bottom of the page was 2002.
My problem is one that I feel should be simple to solve, but not having much
spss syntax background, I'm not sure how to make it work.
I have a list of accounts, and various prices associated with them. In java,
if I wanted to apply something to each group of accounts, I would use a
loop.
(for i <=n
         total = cost[i] + total
 )
or something along those lines. Essentially, I am trying to get the program
to put the total of the whole account on every line for that account.
I have tried the casestovars command, but it is not quite the format I am
looking for.
Any help would be greatly appreciated.

Thanks a lot

Tiffany