DATA Step, Macro, Functions and more

Max and Min for all variables proc means

Accepted Solution Solved
Reply
Contributor
Posts: 38
Accepted Solution

Max and Min for all variables proc means

Hi for all!

 

I have a dataset with numeric values. I think proc means its easier for do it

 

data one;
input var1-var9 @@;
datalines;
9	2	6	8	8	9	7	8	2
9	9	6	6	10	6	0	2	5
4	5	3	4	4	4	7	10	3
4	9	3	8	7	3	7	2	9
6	10	2	6	6	5	8	10	8
0	3	10	9	9	9	9	1	0
6	2	9	6	9	3	1	0	7
4	7	9	2	8	10	10	0	10
3	8	1	10	0	5	10	8	2
9	1	5	9	7	3	0	3	6
0	1	0	9	3	10	3	0	2

;
run;


proc means data=one noprint max min MAXDEC = 0 ; OUTPUT OUT=temp(drop=_type_  _freq_) max=  min=;run;

But i have error (varn it's already defined) How can i obtain dataset like this

 

 

 


max	9	10	10	10	10	10	10	10	10
min	0	1	0	2	0	3	0	0	0

 

thanks

 

 


Accepted Solutions
Solution
‎11-16-2017 03:32 PM
PROC Star
Posts: 549

Re: Max and Min for all variables proc means

something like this.

data one;
infile datalines dlm='09'x ;
input var1-var9 @@ ;
datalines;
9	2	6	8	8	9	7	8	2
9	9	6	6	10	6	0	2	5
4	5	3	4	4	4	7	10	3
4	9	3	8	7	3	7	2	9
6	10	2	6	6	5	8	10	8
0	3	10	9	9	9	9	1	0
6	2	9	6	9	3	1	0	7
4	7	9	2	8	10	10	0	10
3	8	1	10	0	5	10	8	2
9	1	5	9	7	3	0	3	6
0	1	0	9	3	10	3	0	2

;
proc means data=one noprint max min MAXDEC = 0 ; 


OUTPUT OUT=temp (where=( _stat_= "MIN" or _stat_= "MAX" ) drop=_type_  _freq_ );

run;

View solution in original post


All Replies
Super User
Posts: 24,010

Re: Max and Min for all variables proc means

Use the ODS table instead of the OUTPUT table which isn't structured the way you want it, in conjunction with the STACKODS option. 

 

http://support.sas.com/documentation/cdl/en/proc/65145/HTML/default/viewer.htm#p17h6q7ygvkl1sn13qzf9...

 


dali74 wrote:

Hi for all!

 

I have a dataset with numeric values. I think proc means its easier for do it

 

data one;
input var1-var9 @@;
datalines;
9	2	6	8	8	9	7	8	2
9	9	6	6	10	6	0	2	5
4	5	3	4	4	4	7	10	3
4	9	3	8	7	3	7	2	9
6	10	2	6	6	5	8	10	8
0	3	10	9	9	9	9	1	0
6	2	9	6	9	3	1	0	7
4	7	9	2	8	10	10	0	10
3	8	1	10	0	5	10	8	2
9	1	5	9	7	3	0	3	6
0	1	0	9	3	10	3	0	2

;
run;


proc means data=one noprint max min MAXDEC = 0 ; OUTPUT OUT=temp(drop=_type_  _freq_) max=  min=;run;

But i have error (varn it's already defined) How can i obtain dataset like this

 

 

 


max	9	10	10	10	10	10	10	10	10
min	0	1	0	2	0	3	0	0	0

 

thanks

 

 


 

Contributor
Posts: 38

Re: Max and Min for all variables proc means

But i would like to save dataset.

 

 

I saw this option:

 

https://blogs.sas.com/content/sgf/2015/07/17/customizing-output-from-proc-means/

Super User
Posts: 24,010

Re: Max and Min for all variables proc means

It does save as a data set!

But @kiranv_ answer is better.

 


dali74 wrote:

But i would like to save dataset.

 

 

I saw this option:

 

https://blogs.sas.com/content/sgf/2015/07/17/customizing-output-from-proc-means/


 

Super Contributor
Super Contributor
Posts: 269

Re: Max and Min for all variables proc means

If all you want to do is make a data set you could do:

 

data two;
	set one;
	mymax = max (of var1-var9);
	mymin = min (of var1-var9);
	drop var1-var9;
run;
 

I feel i would be negligent if i didn't say your data structure could use improvement.  By that I mean I would advise having a key in the form of a record id.

 

 

Contributor
Posts: 38

Re: Max and Min for all variables proc means

See @kiranv_ solution!

Super User
Posts: 24,010

Re: Max and Min for all variables proc means

@HB Min/Max in a data step wouldn't work the same way, those are row wise operations. 

 

Super Contributor
Super Contributor
Posts: 269

Re: Max and Min for all variables proc means

[ Edited ]

@Reeza I assumed he was min-maxing by row.  Apparently he is min-maxing by column.  It would be nice if posters said what they wanted, wouldn't it?  Lol. 

 

Min-maxing by column means s/he's lucky I didn't post an PROC SQL solution.  Ha.

 

Contributor
Posts: 38

Re: Max and Min for all variables proc means

 
Solution
‎11-16-2017 03:32 PM
PROC Star
Posts: 549

Re: Max and Min for all variables proc means

something like this.

data one;
infile datalines dlm='09'x ;
input var1-var9 @@ ;
datalines;
9	2	6	8	8	9	7	8	2
9	9	6	6	10	6	0	2	5
4	5	3	4	4	4	7	10	3
4	9	3	8	7	3	7	2	9
6	10	2	6	6	5	8	10	8
0	3	10	9	9	9	9	1	0
6	2	9	6	9	3	1	0	7
4	7	9	2	8	10	10	0	10
3	8	1	10	0	5	10	8	2
9	1	5	9	7	3	0	3	6
0	1	0	9	3	10	3	0	2

;
proc means data=one noprint max min MAXDEC = 0 ; 


OUTPUT OUT=temp (where=( _stat_= "MIN" or _stat_= "MAX" ) drop=_type_  _freq_ );

run;
Super User
Posts: 6,934

Re: Max and Min for all variables proc means

Here's a variation on your program that should do the trick:

 

proc means data=one noprint;

var v1-v9;

output out=minimums (drop=_type_ _freq_) min=;

output out=maximums (drop=_type_ _freq_) max=;

run;

 

data want;

set minimums (in=mins) maximums;

if mins then type='min'; else type='max';

run;

Contributor
Posts: 38

Re: Max and Min for all variables proc means

Posted in reply to Astounding
Yes it works fine.

thanks
☑ This topic is solved.

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

Discussion stats
  • 11 replies
  • 387 views
  • 2 likes
  • 5 in conversation