Hi,
I'm looking for a sgplot hbar statement to generate a graph with 7 binary variables. Each variable needs to be shown with both outcomes having each a bar.
A similar graph to the one I have to generate is shown below.
I would appreciate your help
Hi,
try this:
DATA HBAR;
ARRAY _X (*) X1-X7;
DO J=1 TO 100;
DO I=1 TO DIM(_X);
RANDOM=RAND("UNIFORM");
_X(I)=(RAND("UNIFORM") LT RANDOM);
END;
OBS+1;
OUTPUT;
END;
DROP I J RANDOM;
RUN;
PROC TRANSPOSE DATA=HBAR OUT=HBARL;
BY OBS;
VAR X:;
RUN;
PROC SGPLOT DATA=WORK.HBARL;
HBAR _NAME_ / GROUP=COL1 GROUPDISPLAY=CLUSTER COLORSTAT=SUM;
RUN;
Hi acordes,
I'm getting error messages when using this code.
I changes variables in different places and the most often shown error is the variable doesn't exist. However, in the work viewtable, the variable is in.
Could you maybe indicate where each variable goes, maybe there is my mistake.
my 7 variables on the y-axis are supposed to be IL_6_cat, sHER_2neu_cat, VEGF_A_cat, sVEGFR_1_cat, uPA_cat, PLGF_cat, Angiopoietin_cat.
on the x-axis I want to have age or gender.
Thank you for further clarification
Attached is the graph I got.
However, I need 2 bars per variable with the frequency of age on the x-axis, or the frequency of gender.
The 7 y-axis variables are binary with either 0 or 1.
I would appreciate your help.
Thank you
@slg16 wrote:
Attached is the graph I got.
However, I need 2 bars per variable with the frequency of age on the x-axis, or the frequency of gender.
The 7 y-axis variables are binary with either 0 or 1.
I would appreciate your help.
Thank you
And your code looks like?
Did you use a GROUP= with your gender variable? And the Groupdisplay=cluster option?
@ ballardw
This is the code I used as recommended by an earlier comment.
ATA HBAR;
ARRAY Age (*) IL_6_cat sHER_2neu_cat VEGF_A_cat sVEGFR_1_cat uPA_cat PLGF_cat Angiopoietin_cat;
DO J=1 TO 27;
DO I=1 TO 45-75;
RANDOM=RAND("UNIFORM");
Age (I)=(RAND("UNIFORM") LT RANDOM);
END;
OBS+1;
OUTPUT;
END;
DROP I J RANDOM;
RUN;
PROC TRANSPOSE DATA=HBAR OUT=HBARL;
BY Obs;
VAR IL_6_cat sHER_2neu_cat VEGF_A_cat sVEGFR_1_cat uPA_cat PLGF_cat Angiopoietin_cat;
RUN;
PROC SGPLOT DATA=WORK.HBARL;
HBAR _NAME_ / Group=COL1 GROUPDISPLAY=CLUSTER COLORSTAT=SUM;
RUN;
However in the column COL1 I only receive . instead of a 1 or 0.
Where is my mistake?
I started of with the age variable instead of gender
Thank you
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.