I can get separate histograms for each occurrence of the variable "tipo" by using this code
proc sgplot data=dc6 NOAUTOLEGEND;
vbar cod_prob /response=popresidente group=cod_prob;
title justify=center "xxxxx";
xaxis label='probability (%)' labelattrs=(size=7) valueattrs=(size=7);
yaxis label='population' labelattrs=(size=7) valueattrs=(size=7) values=(0 to 15000000 by 1000000);
format popresidente comma10.0;
by tipo;
run;
I wonder whether it is possibile with SAS to obtain a histogram with separate groups of bars, like in graph attached I made by using excel.
Thanks for your help
Leandro D'Aurizio
IVASS (Italy)
/*
I think your code is enough to get this kind of graph.
*/
proc format;
value cod_prob
1='0.00-0.05'
2='0.05-0.10'
3='0.10-0.15'
4='0.15-0.20'
;
value tipo
1='MPS04(median)'
2='PRASSE'
3='MPS19(mean)'
;
run;
data dc6;
call streaminit(123);
do tipo=1 to 3;
do cod_prob=1 to 4;
popresidente=rand('integer',1,100000);
output;
end;
end;
format tipo tipo. cod_prob cod_prob.;
run;
proc sgplot data=dc6 ;
vbar cod_prob /response=popresidente group=tipo groupdisplay=cluster;
title justify=center "xxxxx";
xaxis label='probability (%)' labelattrs=(size=7) valueattrs=(size=7);
yaxis label='population' labelattrs=(size=7) valueattrs=(size=7) ;
format popresidente comma10.0;
run;
In a DATA step, create a new variable which is the combination of the two classification variables.
new_class_var = cats(tipo,'/'second_class_var);
/*
I think your code is enough to get this kind of graph.
*/
proc format;
value cod_prob
1='0.00-0.05'
2='0.05-0.10'
3='0.10-0.15'
4='0.15-0.20'
;
value tipo
1='MPS04(median)'
2='PRASSE'
3='MPS19(mean)'
;
run;
data dc6;
call streaminit(123);
do tipo=1 to 3;
do cod_prob=1 to 4;
popresidente=rand('integer',1,100000);
output;
end;
end;
format tipo tipo. cod_prob cod_prob.;
run;
proc sgplot data=dc6 ;
vbar cod_prob /response=popresidente group=tipo groupdisplay=cluster;
title justify=center "xxxxx";
xaxis label='probability (%)' labelattrs=(size=7) valueattrs=(size=7);
yaxis label='population' labelattrs=(size=7) valueattrs=(size=7) ;
format popresidente comma10.0;
run;
Thanks! It works perfectly.
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.