BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dali74
Fluorite | Level 6

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
kiranv_
Rhodochrosite | Level 12

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

11 REPLIES 11
Reeza
Super User

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

 

 


 

dali74
Fluorite | Level 6

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/

Reeza
Super User

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/


 

HB
Barite | Level 11 HB
Barite | Level 11

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.

 

 

dali74
Fluorite | Level 6

See @kiranv_ solution!

Reeza
Super User

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

 

HB
Barite | Level 11 HB
Barite | Level 11

@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.

 

dali74
Fluorite | Level 6
 
kiranv_
Rhodochrosite | Level 12

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;
Astounding
PROC Star

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;

dali74
Fluorite | Level 6
Yes it works fine.

thanks

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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