BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
kindbe17
Fluorite | Level 6

Hi everyone, could you please help me to use proc sql, create new variables (not macro) that will keep N, Mean, STD, Median, Min, Max of SALARY by LEAGUEs from sashelp.BASEBALL dataset.

i tried this but seems i should have not use proc means;

 

proc means data=sashelp.baseball;

output out=baseball_1 N=N1 Mean=Mean1 STD=STD1 Median=Median1 Min=Min1 Max=Max1;

class league;

var salary;

run;

 

proc sql;

create table baseball_2 as

select League. *,

N1 as N,

Mean1 as Mean,

STD1 as STD,

Median1 as Median,

Min1 as Min,

Max1 as Max

FROM baseball_1;

quit;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
proc sql;
create table baseball_2 as
  select
    league,
    min(salary) as min
  from sashelp.baseball
  group by league
;
quit;

Add other SQL summary functions as documented here.

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

Do you want to create the statistics in PROC SQL or simply keep the variables that PROC SUMMARY produces?

 

In the second case, there is no need to use PROC SQL at all. Simply use a keep = option in the PROC SUMMARY Output Statement.

kindbe17
Fluorite | Level 6

yes, i want to create the statistics in Proc SQL.

AhmedAl_Attar
Rhodochrosite | Level 12

@kindbe17 

I believe this is what you are looking for

proc sql;
	create table baseball_sql as
	select league,
		n(salary) as N,
		Mean(salary) as Mean,
		STD(salary) as STD,
		Median(salary) as Median,
		Min(salary) as Min,
		Max(salary) as Max
	FROM sashelp.baseball
	Group by league
	Order by league;
quit;
/* vs. */
proc means data=sashelp.baseball NWAY missing;
	output out=baseball_means(drop=_:) N=N1 Mean=Mean1 STD=STD1 Median=Median1 Min=Min1 Max=Max1;
	class league;
	var salary;
run;

Hope this helps

Kurt_Bremser
Super User
proc sql;
create table baseball_2 as
  select
    league,
    min(salary) as min
  from sashelp.baseball
  group by league
;
quit;

Add other SQL summary functions as documented here.

ballardw
Super User

@kindbe17 wrote:

Hi everyone, could you please help me to use proc sql, create new variables (not macro) that will keep N, Mean, STD, Median, Min, Max of SALARY by LEAGUEs from sashelp.BASEBALL dataset.

i tried this but seems i should have not use proc means;

 


Why not? From the SQL you show I would think that:

proc means data=sashelp.baseball;
  output out=baseball_1 (drop=_type_ _freq_)
        N=N Mean=Mean STD=STD Median=Median Min=Min Max=Max
  ;
  class league;
  var salary;
run;

Would be sufficient.

If you don't actually want the total row for all leagues then add NWAY to the Proc Means statement.

 

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
  • 6 replies
  • 460 views
  • 0 likes
  • 5 in conversation