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;
You could create a new variable which is the character variable equivalent of numeric variable GROUP_ID.
You could create a new variable which is the character variable equivalent of numeric variable GROUP_ID.
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
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;
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.).
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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.