I am trying to display the labels on my bar graph with n and percent combined. Using SAS support community
I was able to locate this solution:
https://communities.sas.com/t5/SAS-Programming/Making-a-grouped-bar-chart-with-both-count-and-percent-in/m-p/521667
The solution works great the problem is when the percent are transposed the values are not coming out as they should. I also have several observation
and some percent's get numeric values with many decimal places (1.6198704104) when I would like 1.6.
My data is as follows:
data bar; infile datalines dlm=','; input Country $ Q1_2022_n Q1_2022_pct Q2_2023_n Q2_2023_pct num_change pct_change;
datalines; Australia,30, 1.6, 33, 1.8, 3, 0.2 Belgium, 8, 0.4, 11, 0.6, 3, 0.2 Canada, 160, 8.7, 157, 8.7, -3, 0.0 ; run;
So for the first line when the variables are combined I would like 30(1.6), 33(1.8) and 3(0.2) instead
I get 30(10.8), 33(11.8) and 1.8(11.6). My code so far is below.
data bar; infile datalines dlm=','; length country $10.; input Country $ Q1_2022_n Q1_2022_pct Q2_2023_n Q2_2023_pct num_change pct_change; datalines; Australia,30, 1.6, 33, 1.8, 3, 0.2 Belgium, 8, 0.4, 11, 0.6, 3, 0.2 Canada, 160, 8.7, 157, 8.7, -3, 0.0 Netherlands, 79, 4.3, 79, 4.4, 0, 0.1 ; run; proc sort data = bar; by country; run; proc transpose data=bar out=bar_long(rename=(_NAME_=Group COL1=value)); by country; run; proc sql; create table bar_cat as select *, cats(value, "(", put(value/(sum(value)), percent10.1), ")") as datalabel from bar_long group by Group; quit;
Any assistance would be great. Thanks in advance.
... View more