BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
braam
Quartz | Level 8

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            
1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

This is for reporting purposes, correct?

 

Also, can you show us some of your data for us to work with?

braam
Quartz | Level 8

@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;
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



braam
Quartz | Level 8

@yabwon 

Oh thanks. That looks what I want to have. Just wondering if I can save it as a SAS dataset?

 

@PaigeMiller 

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;
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 942 views
  • 4 likes
  • 4 in conversation