Thanks for your replies, here is my code (it's easier for me to use a sashelp dataset): data dataset;
set sashelp.class;
run;
/*Age categorization*/
data class;
set dataset;
if Age<=13 then Age_cat='<=13';
else Age_cat='>13';
run;
/*Sex and Age category combined to get a group with 4 levels*/
data class_group;
set class;
if Sex='M' then do;
if Age_cat='<=13' then cat='M - <=13';
else cat='M - >13';
end;
else do;
if Age_cat='<=13' then cat='F - <=13';
else cat='F - >13';
end;
run;
proc sort data=class_group;
by cat;
run;
/*Density plot by group (Plot1)*/
title 'Height of boys and girls according to age category';
proc sgplot data=class_group;
density height /group=cat type=kernel;
xaxis label='HEIGHT';
run;
/*From class_group, 5 subjects have cat='F - <=13' and the total dataset has 19 subjects*/
/*In a histogram, frequencies are computed within each subgroup (Plot 2)*/
title 'Height of boys and girls according to age category';
proc sgplot data=class_group(where=(cat='F - <=13'));
histogram height /group=cat binwidth=10;
xaxis label='HEIGHT' values=(50 to 70 by 10);
run; Plot1 Plot 2 The red lines indicate the bars' heights if frequency of 'F - <=13' was computed on the total dataset (19 subjects) instead of the size of the subgroup (5 subjects). I would like that in the computation of densities for each group these 19 subjects were used, not only those belonging to that particular subgroup. Do I have to use weights? Hope this clarifies a bit my question, thanks you all!!
... View more