BookmarkSubscribeRSS Feed
Phil_NZ
Barite | Level 11

Hi SAS community!

Regarding getting some standard statistics number, I usually proc sort then using proc means to do so.

My data is as below (I also attached a datafile contains one sample of my whole dataset). While Type indicates the companies, Country is 2-digit of country. My column of interest is amihud. The dataset included contains data from a lot of different countries. What I want is to receive some data statistics summary for each country containing: median, mean, p1, p5, p90, p95, p99 of variable amihud (especially it is good if the code relates to proc means)

 

Many thanks in advance!

Type	year	amihud	Country
772086	1989	.	AR
982616	1989	.	AR
982620	1989	.	AR
982629	1989	.	AR
982694	1989	.	AR
992128	1989	.	AR
992156	1989	.	AR
992183	1989	.	AR
992260	1989	.	AR
992280	1989	.	AR
772086	1990	.	AR
982616	1990	.	AR
982620	1990	.	AR
982629	1990	.	AR
982694	1990	.	AR
992128	1990	.	AR
992156	1990	.	AR
992183	1990	.	AR
992260	1990	.	AR
992280	1990	.	AR
772086	1991	.	AR

 
Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
3 REPLIES 3
PaigeMiller
Diamond | Level 26

You show an example where AMIHUD is always missing. I assume that's not always the case. So this ought to work (but I can't test it).

 

proc summary nway data=have;
     class country;
     var amihud;
     output out=_stats_ mean=/autoname;
run;

 

 

--
Paige Miller
ballardw
Super User

Where @PaigeMiller has the Mean= you would place ALL of your desired statistics:

 

median= mean=  p1= p5= p90= p95= p99= /autoname ;

 

The autoname will append the statistic name to the variable so you can tell which stat is which in the data set.

You may want the option NWAY on the proc statement or you will get a summary overall across all countries as well.

PaigeMiller
Diamond | Level 26

Good catch, @ballardw 

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 861 views
  • 2 likes
  • 3 in conversation