BookmarkSubscribeRSS Feed
Wendy13
Calcite | Level 5

I like to create a bar graph for these variables:

acta actb actc actd acte actf

These are types of activity from the survey and I like to graph each frequencies.

I tried following code but it didn't work. Can someone please help me fix this?

title "Question 1";

proc sgplot data=gopintern;

  vbar enta,entb,entc,entd,ente,entf / stat=freq;

  run;

3 REPLIES 3
ballardw
Super User

VBAR wants a SINGLE variable for the Xaxis. To generate multiple bars, one for each of your original variables you would need to add a new variable to your data. Something like:

Data want;

     set have;

     Q1Group = 'enta'; Response=enta;output;

     Q1Group = 'entb'; Response=entb;output;

     Q1Group = 'entc'; Response=entc;output;

     Q1Group = 'entd'; Response=entd;output;

     Q1Group = 'ente'; Response=ente;output;

     Q1Group = 'entf'; Response=entf;output;

run;

Then the VBAR statement would look like using the new data set in the SGPLOT statement

vbar Q1group / stat=freq;

Wendy13
Calcite | Level 5

I tried it, then bar graph shows all same frequency.

Here is code I used:

title "Question 1";

proc sgplot data=gopintern;

  vbar Q1Group / stat=freq;

  run;


ballardw
Super User

Stat=Freq reports how many records have that value. You might need to provide some actual data examples.

BTW, it looks like you have some form of survey software that outputs each response category per question. If this is the case and the values are output as 0/1 for no/yes then use Response=Response and stat=sum OR use Freq=Response statement. If the response categories are values such as list position order we'll need to work on something else.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1006 views
  • 1 like
  • 2 in conversation