home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / bit / listserv / sasl / 3844 < prev    next >
Encoding:
Text File  |  1992-08-22  |  2.2 KB  |  106 lines

  1. Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
  2. Path: sparky!uunet!paladin.american.edu!auvm!LOBBY.TI.COM!RSNYDER
  3. X-Mailer: ELM [version 2.2 PL16]
  4. Message-ID: <9208212332.AA13519@ti.com>
  5. Newsgroups: bit.listserv.sas-l
  6. Date:         Fri, 21 Aug 1992 18:32:57 CDT
  7. Reply-To:     "R. Snyder" <rsnyder@LOBBY.TI.COM>
  8. Sender:       "SAS(r) Discussion" <SAS-L@UGA.BITNET>
  9. From:         "R. Snyder" <rsnyder@LOBBY.TI.COM>
  10. Subject:      Re: I need help with SQL
  11. Comments: To: glg2@GTE.COM
  12. Comments: cc: sas-l@uga.cc.uga.edu
  13. In-Reply-To:  <9208212045.AA06155@ti.com>; from "Gail Gill" at Aug 21,
  14.               92 4:37 pm
  15. Lines: 89
  16.  
  17. CONTENT:   Reply to: "I need help with SQL"
  18. SUMMARY:   Use 'group by' and 'sum' function
  19. E-ADDR:    rsnyder@lobby.ti.com
  20. NAME:      Bob Snyder
  21. COMPANY:   Texas Instruments, Sherman, TX
  22. PHONE:     (903) 868-5799
  23. FAX:       (903) 868-7240
  24.  
  25. Gail Gill writes:
  26. >
  27. > Hello fellow sas-lers,
  28. >   I need some help with using sql.
  29. > The problem is as follows:
  30. >
  31. > My data was entered with multiple records for the same customer,
  32. > I need to modify it.
  33. > It resides as the following:
  34. >
  35. > Cust   item   cost
  36. >  1      A      V
  37. >  1      A      V
  38. >  1      A      V
  39. >  1      B      W
  40. >  1      B      W
  41. >  2      A      V
  42. >  2      C      X
  43. >  2      D      Y
  44. >  2      E      Z
  45. > and so forth.
  46. >
  47. >  What I would like to get is the following:
  48. >
  49. > Cust   item   cost
  50. >  1      A     3*V
  51. >  1      B     2*W
  52. >  2      A      V
  53. >  2      C      X
  54. >  2      D      Y
  55. >  2      E      Z
  56. > and so forth.
  57. >
  58. > Thanks in advance for your assistance.
  59. > Gail Gill
  60. >
  61. Gail,
  62.  
  63. Try the following:
  64.  
  65. data sasuser.gailgill;
  66.  
  67.   length Cust 8 item $ 1 cost 8;
  68.  
  69.   format cost dollar7.2;
  70.  
  71.   input Cust item cost;
  72.  
  73. cards;
  74.  1      A      2.00
  75.  1      A      2.00
  76.  1      A      2.00
  77.  1      B      6.00
  78.  1      B      6.00
  79.  2      A      2.00
  80.  2      C      4.00
  81.  2      D      5.00
  82.  2      E      7.00
  83. ;
  84.  
  85. run;
  86.  
  87. proc sql;
  88.   select cust, item, put( sum(cost), dollar7.2 ) as cost
  89.     from sasuser.gailgill
  90.       group by cust,item;
  91.  
  92. ============================== OUTPUT ===========================
  93.  
  94.     CUST  ITEM  COST
  95.    -----------------------
  96.      1  A       $6.00
  97.      1  B      $12.00
  98.      2  A       $2.00
  99.      2  C       $4.00
  100.      2  D       $5.00
  101.      2  E       $7.00
  102.  
  103. Hope this gets it for you!
  104.  
  105. Bob
  106.