I have a panel dataset, and I'm wondering how I can make table that looks like this. Among others, I tried proc means (with by year), but it doesn't look great though I can see the mean value of variables by year. Does anybody have a good suggestion for me? Thanks in advance.
Variable A Variable B Variable C mean N mean N mean N 2010 2011 2012 2013 2014 2015 2016
Hi @braam ,
How about proc tabulate?
data stocks; set sashelp.stocks;
year=year(date);
run;
proc tabulate data = stocks;
class year;
var open high low;
table year, (open high low)*(mean n);
run;
All the best
Bart
This is for reporting purposes, correct?
Also, can you show us some of your data for us to work with?
@PeterClemmensen Thanks for your reply.
The contents I would like to have should be the same as the outcome of the below code. But, the format doesn't look so great.
Yes, it's mainly for reporting purpose. If possible, it would be also good to have as a SAS dataset for me.
data stocks; set sashelp.stocks;
year=year(date);
run;
proc sort data= stocks;
by year; run;
proc means data= stocks;
by year;
var open high low; run;
But the stocks data set would produce equal N for each variable. Your desired table produces unequal N (I'm assuming) for each variable, otherwise it doesn't make sense to have 3 columns of N. So you need to clarify this, and provide us data that more closely matches your problem.
Hi @braam ,
How about proc tabulate?
data stocks; set sashelp.stocks;
year=year(date);
run;
proc tabulate data = stocks;
class year;
var open high low;
table year, (open high low)*(mean n);
run;
All the best
Bart
Oh thanks. That looks what I want to have. Just wondering if I can save it as a SAS dataset?
You are right. Variables may have different sample size, so I can manipulate the Stocks dataset a bit.
data stocks; set stocks;
if stock= "IBM" then open= .;
run;
If you need dataset try `out=` option:
proc tabulate data = stocks out = table(drop = _:);
class year;
var open high low;
table year, (open high low)*(mean n);
run;
All the best
Bart
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.