Hi,
I would like customize proc univariate output such that it generates a table that has the class variables as row labels and descriptive statistics as the column labels. Is this possible? I plan to use the table to generate a graph, the default output does not arrange the data in a way to make this easy. I am currently copy/pasting the one or two numbers at a time into excel, I figure there must be a better way.
Thank you
Wouldn't something like the following provide what you want?:
data WidgetPrices;
input month_date monyy5. price;
month=put(month_date,monname3.);
cards;
Jan01 2.96
Feb01 3.48
Mar01 4.68
Jan02 5.96
Feb02 2.48
Mar02 2.77
Jan03 1.98
Feb03 3.58
Mar03 2.99
;
proc univariate data=WidgetPrices;
class Month;
var Price;
output out=want mean=mean
median=median
std=std_dev
min=min
max=max
q1=q1
q3=q3;
run;
You will get the quickest and best (usually) if you provide the code you are using, a small set of sample data, and the specific output you want to get.
Hi,
I am looking at widget prices over time, and I would like a table of descriptive statistics by month, here is my code so far.
proc univariate data=WidgetPrices;
class Month;
var Price;
run;
Sample Data:
Jan01 2.96
Feb01 3.48
Mar01 4.68
Jan02 5.96
Feb02 2.48
Mar02 2.77
Jan03 1.98
Feb03 3.58
Mar03 2.99
Desired Output:
Mean Median Std-Dev Min Max Q1 Q3
Jan x x x x x x x
Feb x x x x x x x
Mar x x x x x x x
Wouldn't something like the following provide what you want?:
data WidgetPrices;
input month_date monyy5. price;
month=put(month_date,monname3.);
cards;
Jan01 2.96
Feb01 3.48
Mar01 4.68
Jan02 5.96
Feb02 2.48
Mar02 2.77
Jan03 1.98
Feb03 3.58
Mar03 2.99
;
proc univariate data=WidgetPrices;
class Month;
var Price;
output out=want mean=mean
median=median
std=std_dev
min=min
max=max
q1=q1
q3=q3;
run;
This works very well. When I added a second variable "Cost", only the data for "price" was output to "want". However, If I rerun on cost only I get a table with the correct data.
Thank you!
Try the OUTTABLE option on the PROC statement.
when you have more than one VAR variable, the syntax becomes more complex to keep the same layout, unless you use something like the macro described at
http://www.sascommunity.org/wiki/PROC_MEANS_-_Improve_on_the_default
peterC
and we're hoping to present an update at SAS Global Forum in Florida
(peter and myra)
You might want to consider using PROC SUMMARY (means) because it has the AUTONAME option.
proc summary data=WidgetPrices nway ;
class Month;
var price cost ;
output out=want mean= median= std= min= max= q1= q3= / autoname ;
run;
price_ cost_ price_ cost_ price_ cost_
Obs month _TYPE_ _FREQ_ Mean Mean Median Median StdDev StdDev
1 Feb 1 3 3.18000 1.59000 3.48 1.740 0.60828 0.30414
2 Jan 1 3 3.63333 1.81667 2.96 1.480 2.07368 1.03684
3 Mar 1 3 3.48000 1.74000 2.99 1.495 1.04504 0.52252
price_ price_
Obs Min cost_Min Max cost_Max price_Q1 cost_Q1 price_Q3 cost_Q3
1 2.48 1.240 3.58 1.79 2.48 1.240 3.58 1.79
2 1.98 0.990 5.96 2.98 1.98 0.990 5.96 2.98
3 2.77 1.385 4.68 2.34 2.77 1.385 4.68 2.34
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.