DATA Step, Macro, Functions and more

choose all variables _numeric_ except for variable period

Reply
Contributor
Posts: 47

choose all variables _numeric_ except for variable period

Hi All,

In my data step my period variable is numeric in format yymmdd8. My question is I want to do a proc summary such that:

proc summary data=mydata nvar;
class period;
var _numeric_ (except for period);
output out=mysummary sum=;
run;

Any thoughts?

Thanks,
Sachin
Valued Guide
Posts: 632

Re: choose all variables _numeric_ except for variable period

This comes close, although analysis is done on the CLASS variable it is eliminated from the data set. There is no NVAR option (that I know of).
[pre]proc summary data=sashelp.class;* nvar;
class age;
var _numeric_;
output out=mysummary(drop=age_Smiley Happy
sum=/autoname;
run;
proc print data=mysummary;
run;[/pre]
Contributor
Posts: 47

Re: choose all variables _numeric_ except for variable period

Appreciate the response.

and sorry that was meant to be nway. What does sum=/autoname do?

Thanks,
Sachin
Contributor
Posts: 47

Re: choose all variables _numeric_ except for variable period

and the drop=age_: while Im at it. Not sure what it does specifically.

Thanks again
Valued Guide
Posts: 632

Re: choose all variables _numeric_ except for variable period

The autoname option allows MEANS/SUMMARY to name the output variables - very handy for an automated session. Without it you MUST name the new variables if there is more than one analysis variable. The resultant naming convention is always analysisvar_statistic (such as AGE_SUM). In our case we want to drop all statistics (in the example there is only SUM) that are associated with AGE. This list of variables can be abbreviated by specifying AGE_: (the colon essentially says all variables that start with AGE_).
Super User
Posts: 9,662

Re: choose all variables _numeric_ except for variable period

Then chang to use proc means;
[pre]

proc format;
value fmt
low-100 = 'thin'
101 - high='fat'
;
run;
proc means data=sashelp.class nway noprint;
class weight;
output out=mysummary sum= /autoname;
format weight fmt.;
run;
[/pre]


Ksharp Message was edited by: Ksharp
Super User
Posts: 10,466

Re: choose all variables _numeric_ except for variable period

If your original is doing most of what you want all you actually want to do is ignore the variable then drop it from analysis:

proc summary data=mydata (drop=period) nvar;

Frequent Contributor
Posts: 91

Re: choose all variables _numeric_ except for variable period

Actually, since you are using period as your class variable, PROC SUMMARY will essentially ignore "period" as one of the _numeric_ variables and will issue the following:

WARNING: Variable period already exists on file WORK.MYSUMMARY.

WARNING: The duplicate variables will not be included in the output data set of the output statement number 1.

Ask a Question
Discussion stats
  • 7 replies
  • 3876 views
  • 2 likes
  • 5 in conversation