Hello
I have a summary table (data set) with number of customers in each category (Z1,Z2).
What is the way to dispaly this table with percent from total.
So in first row I expect to get:
A Q1 500/2000 300/2000 200/2000 400/2000 600/2000
in second row i expect to see
A Q2 600/3200 200/3200 1200/3200 900/3200 300/3200
and so on
Data have;
Input Z1 $ Z2 $ X1 X2 X3 X4 X5;
cards;
A Q1 500 300 200 400 600
A Q2 600 200 1200 900 300
A Q3 300 200 200 700 1000
B Q1 500 800 1300 1000 1500
B Q2 400 200 300 600 500
B Q3 500 600 800 700 300
C Q1 900 800 300 800 1200
C Q2 400 200 700 200 700
C Q3 400 500 600 300 600
;
Run;
data want;
set have;
array x{*} x:;
array y{5} y1-y5;
format y: percent7.2;
do i = 1 to 5;
y{i} = x{i} / sum(of x{*});
end;
drop i;
run;
Do you want this in a data set ?
So the fractions will be character values, right?
data want;
set have;
array x{*} x:;
array y{5} y1-y5;
format y: percent7.2;
do i = 1 to 5;
y{i} = x{i} / sum(of x{*});
end;
drop i;
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.