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
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;
Use the ODS table instead of the OUTPUT table which isn't structured the way you want it, in conjunction with the STACKODS option.
@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
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/
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/
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.
See @kiranv_ solution!
@HB Min/Max in a data step wouldn't work the same way, those are row wise operations.
@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.
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;
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.