BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DmytroYermak
Lapis Lazuli | Level 10

Hi all,

 

Could you please help to transpose the table below as picture - the algorythm. I have attached a code as well. Should it be proc transpose or arrays are more applicable here. Thank you!

 

 

1.jpg

data test;
	infile datalines;
	input cat1 cat2 min max mean;
datalines;
1	1	1	9	5
1	2	2	7	4
1	3	3	8	5
1	4	2	8	5
1	5	2	9	4
1	6	1	7	5
1	7	2	9	4
1	8	3	8	4
2	1	4	7	5
2	2	1	8	6
2	3	2	9	5
2	4	3	8	6
2	6	3	8	6
2	7	1	7	5
2	8	2	9	5
3	1	2	7	4
3	3	3	8	5
3	4	3	9	6
3	5	1	8	5
3	6	3	9	4
3	7	1	7	5
3	8	2	9	6
;
run; 

 

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

 

 

proc transpose data=test out=test2 prefix=_;
   by cat1;
   id cat2;
   var min max mean;
   run;

2017-10-17_7-43-59.png

View solution in original post

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Like any process, get your data as you want, then process it:

data inter;
  set have;
  select(cat1);
    when (1) res=max; 
    when (2) res=min;
    when (3) res=median;
   otherwise;
  end;
run;

proc transpose data=inter out=want;
  by cat1;
  var res;
  id cat2;
run;

Then you just format cat1 using the text min/max/median 1/2/3.

DmytroYermak
Lapis Lazuli | Level 10

Hi RW9. Thank you for your code. The matter is that the CAT1 does not correspond to Min, Max and Mean. It is just a coincidence. The CAT1 should be left as is.

data_null__
Jade | Level 19

 

 

proc transpose data=test out=test2 prefix=_;
   by cat1;
   id cat2;
   var min max mean;
   run;

2017-10-17_7-43-59.png

data_null__
Jade | Level 19

Use PROC TRANSPOSE NAME= option to change variable _NAME_ to Statistics

 

proc transpose name=statistics ...
Ksharp
Super User

It is very simple for PROC TRANSPOSE .

 

data test;
	infile datalines;
	input cat1 cat2 min max mean;
datalines;
1	1	1	9	5
1	2	2	7	4
1	3	3	8	5
1	4	2	8	5
1	5	2	9	4
1	6	1	7	5
1	7	2	9	4
1	8	3	8	4
2	1	4	7	5
2	2	1	8	6
2	3	2	9	5
2	4	3	8	6
2	6	3	8	6
2	7	1	7	5
2	8	2	9	5
3	1	2	7	4
3	3	3	8	5
3	4	3	9	6
3	5	1	8	5
3	6	3	9	4
3	7	1	7	5
3	8	2	9	6
;
run; 
proc transpose data=test out=want;
by cat1;
id cat2;
var min max mean;
run;
DmytroYermak
Lapis Lazuli | Level 10

Thank you for the explanations! It has worked.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1683 views
  • 0 likes
  • 4 in conversation