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

Good morning, 

 

I have a problem with the PROC MEANS procedure. 

 

The problem is that I have a table with two variables

 -cod (is a code, numeric) 

 -cod2 (is another code, numeric) 

 

What I want to do is to make a PROC MEANS summarizing by cod and cod2. But PROC MEANS procedure gives me the variables _TYPE_ and _FREQ_ summarizing the variable cod and then the variable cod2 instead of doing together. 

 

My code is: 

proc means data=data.table1 noprint;
class cod cod2;
output out=data.table2;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
CeliaAlonso
Calcite | Level 5

I get the solution it was doing this: 

proc summary data=data.table1 print; 
by cod cod2;
output out=data.table2; 
run;

 

Thanks for help anyways Smiley Very Happy

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please provide test data in the form of a datastep (or use sashelp.xyz), as this helps us see what you have, and show what you want out.  You say you want to summarise cod and cod2, to which statistics?  _type_ and _freq_ are SAS derived variables, you can get stats out by (going to assume a few basic ones):

proc means data=data.table1 noprint; 
  var cod cod2;
  output out=data.table2 / n=n mean=mean median=median stddev=stddev min=min max=max; 
run;

This will give you a table (assumption as not seen data!) with cod and cod2 on two obs with the given stats as variables.  You can read in the manual further examples and full documentation.

http://documentation.sas.com/?docsetId=proc&docsetTarget=n1qnc9bddfvhzqn105kqitnf29cp.htm&docsetVers...

CeliaAlonso
Calcite | Level 5

I get the solution it was doing this: 

proc summary data=data.table1 print; 
by cod cod2;
output out=data.table2; 
run;

 

Thanks for help anyways Smiley Very Happy

Reeza
Super User

Several ways:

  • Use the NWAY option on the PROC MEANS statement so you only have the highest level.
  • Use the WAYS or TYPES statement to explicitly control the levels
  • Use a BY statement instead of CLASS
  • Use a PROC SQL instead if only doing a single statistics it's relatively easy.

 


@CeliaAlonso wrote:

Good morning, 

 

I have a problem with the PROC MEANS procedure. 

 

The problem is that I have a table with two variables

 -cod (is a code, numeric) 

 -cod2 (is another code, numeric) 

 

What I want to do is to make a PROC MEANS summarizing by cod and cod2. But PROC MEANS procedure gives me the variables _TYPE_ and _FREQ_ summarizing the variable cod and then the variable cod2 instead of doing together. 

 

My code is: 

proc means data=data.table1 noprint;
class cod cod2;
output out=data.table2;
run;

 


 

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
  • 3 replies
  • 489 views
  • 0 likes
  • 3 in conversation