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!
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=test2 prefix=_;
by cat1;
id cat2;
var min max mean;
run;
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.
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.
proc transpose data=test out=test2 prefix=_;
by cat1;
id cat2;
var min max mean;
run;
Use PROC TRANSPOSE NAME= option to change variable _NAME_ to Statistics
proc transpose name=statistics ...
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;
Thank you for the explanations! It has worked.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.