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

Hello,

 

I have a dataset with many variables and obsevations. Most variables are numeric, but not all. I Use the proc summary to collapse data by a Class variable. The Class variable is also numeric and represents the ID för members of a define group (group_ID). Is there any way to exclude the group_ID variable (which is numeric) from the Var statement? The reason why each variable is not written in the Var statement is because they are so many.

Thanks!

 

proc summary data=x;

var _numeric_

class group_ID;

ouput out=Y;

RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You could create a new variable which is the character variable equivalent of numeric variable GROUP_ID.

 

 

--
Paige Miller

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

You could create a new variable which is the character variable equivalent of numeric variable GROUP_ID.

 

 

--
Paige Miller
MCB1
Fluorite | Level 6

Thanks, it is the easy way out. I hoped there was a way to avoid the transformation af the Group_ID from numeric to character.

/MCB

Kurt_Bremser
Super User

Since you will never use a group variable for calculations, such variables should always be stored as character. Fix that in your import process.

 

Alternatively, you will need to grab the names of all numeric variables from DICTIONARY.COLUMNS into a macro variable, excluding your group variable. The macro variable is then used in place of _numeric_:

proc sql noprint;
select name into :varnames separated by " "
from dictionary.columns
where libname = "WORK" and memname = "X" and type = "num" and upcase(name) ne "GROUP_ID";
quit;

proc summary data=x;
var &varnames.;
class group_ID;
output out=Y;
run;
MCB1
Fluorite | Level 6
Thanks! I will try this solution as well. But you are right, I could tranfrom the Group_ID to a character.
FreelanceReinh
Jade | Level 19

Hello @MCB1,

 

Another simple solution would be to use one or two name range lists in the VAR statement. If group_ID is the first or last numeric variable (in terms of logical position in the data set, see PROC CONTENTS output using the VARNUM option), a single list is sufficient, otherwise two.

 

Example: Suppose that group_ID is the sixth of, say, eight or more variables. Then your VAR statement excluding it would look like this:

 

var firstvar-numeric-fifthvar seventhvar-numeric-lastvar;

(with the actual variable names instead of firstvar, fifthvar, etc.).

 

MCB1
Fluorite | Level 6
Thank you, it is a good idea as well.
data_null__
Jade | Level 19

Use PROC MEANS.  The default is to summarize all numeric variable NOT mentioned in other statements.

 

ods select none;
proc means stackods data=sashelp.class;
   class age;
   ods output summary=summary;
   run;
ods select all;
proc print;
   run;

Capture.PNG

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 7 replies
  • 1405 views
  • 3 likes
  • 5 in conversation