BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
leandro4
Calcite | Level 5

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)

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
/*
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;

Ksharp_0-1700991568762.png

 

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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);
--
Paige Miller
Ksharp
Super User
/*
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;

Ksharp_0-1700991568762.png

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1544 views
  • 1 like
  • 3 in conversation