Hello
What is the way to create such report when for each day there is freq report by 3 fields: X1,X2,X3.
For each day we need to see the fields names and categories names and need to have a black column as a gap between days.
Data rawtbl;
input ID date : date9. x1 $ x2 $ x3 $ ;
cards;
1 01jan2021 a a b
2 01jan2021 b c b
3 01jan2021 c a b
4 01jan2021 a c c
5 02an2021 b b b
6 02an2021 a c b
7 03jan2021 c a b
8 03jan2021 a b b
9 03jan2021 a a c
;
run;
Check next code:
Data rawtbl;
input ID date : date9. x1 $ x2 $ x3 $ ;
format date ddmmyy10.;
cards;
1 01jan2021 a a b
2 01jan2021 b c b
3 01jan2021 c a b
4 01jan2021 a c c
5 02jan2021 b b b
6 02jan2021 a c b
7 03jan2021 c a b
8 03jan2021 a b b
9 03jan2021 a a c
;
run;
proc format lib=work;
value $catg
'a' = 'x_a'
'b' = 'x_b'
'c' = 'x_c'
; run;
data to_rep;
set rawtbl;
length category $3;
category = put(x1,$catg.); field='x1'; freq=1; output;
category = put(x2,$catg.); field='x2'; freq=1; output;
category = put(x3,$catg.); field='x3'; freq=1; output;
drop x1 - x3;
run;
proc tabulate data=to_rep;
class date field category;
var freq;
table field*category,
date*freq*sum=' ';
run;
Check next code:
Data rawtbl;
input ID date : date9. x1 $ x2 $ x3 $ ;
format date ddmmyy10.;
cards;
1 01jan2021 a a b
2 01jan2021 b c b
3 01jan2021 c a b
4 01jan2021 a c c
5 02jan2021 b b b
6 02jan2021 a c b
7 03jan2021 c a b
8 03jan2021 a b b
9 03jan2021 a a c
;
run;
proc format lib=work;
value $catg
'a' = 'x_a'
'b' = 'x_b'
'c' = 'x_c'
; run;
data to_rep;
set rawtbl;
length category $3;
category = put(x1,$catg.); field='x1'; freq=1; output;
category = put(x2,$catg.); field='x2'; freq=1; output;
category = put(x3,$catg.); field='x3'; freq=1; output;
drop x1 - x3;
run;
proc tabulate data=to_rep;
class date field category;
var freq;
table field*category,
date*freq*sum=' ';
run;
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.