DATA Step, Macro, Functions and more

choose all variables _numeric_ except for variable period

Accepted Solution Solved
Reply
Contributor
Posts: 47
Accepted Solution

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

Accepted Solutions
Solution
‎10-03-2017 08:19 AM
Frequent Contributor
Posts: 91

Re: choose all variables _numeric_ except for variable period

Posted in reply to SachinRuk

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.

View solution in original post


All Replies
Valued Guide
Posts: 634

Re: choose all variables _numeric_ except for variable period

Posted in reply to SachinRuk
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

Posted in reply to SachinRuk
and the drop=age_: while Im at it. Not sure what it does specifically.

Thanks again
Valued Guide
Posts: 634

Re: choose all variables _numeric_ except for variable period

Posted in reply to SachinRuk
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: 10,041

Re: choose all variables _numeric_ except for variable period

Posted in reply to SachinRuk
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: 11,343

Re: choose all variables _numeric_ except for variable period

Posted in reply to SachinRuk

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;

Solution
‎10-03-2017 08:19 AM
Frequent Contributor
Posts: 91

Re: choose all variables _numeric_ except for variable period

Posted in reply to SachinRuk

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 5281 views
  • 2 likes
  • 5 in conversation