BookmarkSubscribeRSS Feed
Gladis6680
Obsidian | Level 7

Hi SAS Community,

 

I had a question regarding the layout of a table.

 

I have a data set, this is obtained after doing a proc summary on BEVERAGES

 

proc summary data=HAVE nway;

class Beverages;

var SALES;

by FISCAL_PERIOD;

output out=TABLE sum=;

run;

 

This is what it looks like

FISCAL_PRIODBEVERAGESALES
JANCoffee$20
JANTea$50
JANMilk$70
JANLatte$100
JANJuice$50
JANHot Chocolate$30
JANMilk$60
JANMocha$35
FEBMilk$30
FEBLatte$50
FEBJuice$60
FEBHot Chocolate$55
MARCoffee$33
MARTea$55
MARMilk$85
MARLatte$200
APRILMilk$70
APRILLatte$100
APRILJuice$50
APRILHot Chocolate$30
MAYCappuccino$25
MAYDouble expresso$33
MAYlatte macchiato$45
MAYJuice$60
MAYHot Chocolate$55
JUNELatte$100
JUNEJuice$50
JUNEHot Chocolate$30
JUNEMilk$60
JUNEMocha$35

 

But I would like it to look like the table below

 

 

BEVERAGESJANFEBMARCHAPRILMAYJUNE
Cappuccino    $25 
Double expresso    $33 
Coffee$20 $33   
Tea$50 $55   
Milk$70$30$85$70  
Latte$100$50$200$100 $100
latte macchiato    $45 
Juice$50$60 $50$60$50
Hot Chocolate$30$55 $30$55$30
Milk$60    $60
Mocha$35    $35

 

I have tried

PROC FREQ data=TABLE;

tables BEVERAGES*FISCAL_PERIOD;

run;

 

The above just gives me the count and not the sum.

I would appreciate your help.

Thanks

 

4 REPLIES 4
tomrvincent
Rhodochrosite | Level 12
use PROC TABULATE instead.
Reeza
Super User
You can WEIGHT with the SALES to get the values. If you have negative values do not do this though. Otherwise, PROC TABULATE is a an option if you want displayed output. If you want a table instead, use PROC TRANSPOSE.
ballardw
Super User

Note that getting character values like Jan Feb and such to sort properly is going to be a problem. So are your Fiscal_Period values character?

 

If they are character, I want to see how you got your shown order for the output of Proc Summary.

 

 

If the purpose is a report then something like:

proc tabulate data= have;
   class beverages fiscal_period;
   var sales;
   table  beverages=' ',
          fiscal_period=' '*sales=' '*sum=' '
          /box=beverages misstext=' '
   ;
run;

can get you started but there may be some order issues.

Gladis6680
Obsidian | Level 7

Thank you! I will work on the proc tabulate. I converted the FISCAL_PERIOD into Format=MONYY7. The type is numeric

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 583 views
  • 0 likes
  • 4 in conversation