home *** CD-ROM | disk | FTP | other *** search
- Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
- Path: sparky!uunet!paladin.american.edu!auvm!LOBBY.TI.COM!RSNYDER
- X-Mailer: ELM [version 2.2 PL16]
- Message-ID: <9208212332.AA13519@ti.com>
- Newsgroups: bit.listserv.sas-l
- Date: Fri, 21 Aug 1992 18:32:57 CDT
- Reply-To: "R. Snyder" <rsnyder@LOBBY.TI.COM>
- Sender: "SAS(r) Discussion" <SAS-L@UGA.BITNET>
- From: "R. Snyder" <rsnyder@LOBBY.TI.COM>
- Subject: Re: I need help with SQL
- Comments: To: glg2@GTE.COM
- Comments: cc: sas-l@uga.cc.uga.edu
- In-Reply-To: <9208212045.AA06155@ti.com>; from "Gail Gill" at Aug 21,
- 92 4:37 pm
- Lines: 89
-
- CONTENT: Reply to: "I need help with SQL"
- SUMMARY: Use 'group by' and 'sum' function
- E-ADDR: rsnyder@lobby.ti.com
- NAME: Bob Snyder
- COMPANY: Texas Instruments, Sherman, TX
- PHONE: (903) 868-5799
- FAX: (903) 868-7240
-
- Gail Gill writes:
- >
- > Hello fellow sas-lers,
- > I need some help with using sql.
- > The problem is as follows:
- >
- > My data was entered with multiple records for the same customer,
- > I need to modify it.
- > It resides as the following:
- >
- > Cust item cost
- > 1 A V
- > 1 A V
- > 1 A V
- > 1 B W
- > 1 B W
- > 2 A V
- > 2 C X
- > 2 D Y
- > 2 E Z
- > and so forth.
- >
- > What I would like to get is the following:
- >
- > Cust item cost
- > 1 A 3*V
- > 1 B 2*W
- > 2 A V
- > 2 C X
- > 2 D Y
- > 2 E Z
- > and so forth.
- >
- > Thanks in advance for your assistance.
- > Gail Gill
- >
- Gail,
-
- Try the following:
-
- data sasuser.gailgill;
-
- length Cust 8 item $ 1 cost 8;
-
- format cost dollar7.2;
-
- input Cust item cost;
-
- cards;
- 1 A 2.00
- 1 A 2.00
- 1 A 2.00
- 1 B 6.00
- 1 B 6.00
- 2 A 2.00
- 2 C 4.00
- 2 D 5.00
- 2 E 7.00
- ;
-
- run;
-
- proc sql;
- select cust, item, put( sum(cost), dollar7.2 ) as cost
- from sasuser.gailgill
- group by cust,item;
-
- ============================== OUTPUT ===========================
-
- CUST ITEM COST
- -----------------------
- 1 A $6.00
- 1 B $12.00
- 2 A $2.00
- 2 C $4.00
- 2 D $5.00
- 2 E $7.00
-
- Hope this gets it for you!
-
- Bob
-