BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tgrandchamp
Fluorite | Level 6

Greetings and Thanks in advance for the help. I feel like I am hung up on an issue that will be simple and obvious if someone can explain it to me. I am attempting to produce a simple bar graph from a data field that has been modified using a PROC format statement. However the bar graph is showing incorrectly (the format level range with the "high" designation is repeated numerous times and the frequencies for all ranges are off. Below is the an example of the code I am using with the example sashelp.cars dataset. along with the incorrect graphing output compared to the correct PROC FREQ output. How do I get my PROC GCHART output to match the PROC FREQ output?

 

PROC FORMAT;

VALUE Price low-20000 = '0-20K'

            20000<-35000 = '20K-35K'

            35000<-50000 = '35K-50k'

            50000<-high = '50K+';

RUN;

 

DATA work.cars;

     SET sashelp.cars;

     FORMAT MSRP Price.;

RUN;

 

PROC FREQ DATA=work.Cars;

     Tables MSRP / NOPERCENT NOCUM;

RUN;

 

PROC GCHART DATA=work.Cars;

     VBAR MSRP;

RUN;

QUIT;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Looks like GCHART doesn't recognize the format for some reason. 

 

I would probably just switch to SGPLOT - which you should do anyways - and use that instead. You get better graphics and it's easier to work with. You'll find a lot of old courses and tutorials still reference the SAS/GRAPH procedures since the language is almost 50 years old now. 

 

PROC sgplot DATA=work.Cars;

     VBAR MSRP/ stat=freq;

RUN;

 


@tgrandchamp wrote:

Greetings and Thanks in advance for the help. I feel like I am hung up on an issue that will be simple and obvious if someone can explain it to me. I am attempting to produce a simple bar graph from a data field that has been modified using a PROC format statement. However the bar graph is showing incorrectly (the format level range with the "high" designation is repeated numerous times and the frequencies for all ranges are off. Below is the an example of the code I am using with the example sashelp.cars dataset. along with the incorrect graphing output compared to the correct PROC FREQ output. How do I get my PROC GCHART output to match the PROC FREQ output?

 

PROC FORMAT;

VALUE Price low-20000 = '0-20K'

            20000<-35000 = '20K-35K'

            35000<-50000 = '35K-50k'

            50000<-high = '50K+';

RUN;

 

DATA work.cars;

     SET sashelp.cars;

     FORMAT MSRP Price.;

RUN;

 

PROC FREQ DATA=work.Cars;

     Tables MSRP / NOPERCENT NOCUM;

RUN;

 

PROC GCHART DATA=work.Cars;

     VBAR MSRP;

RUN;

QUIT;

 

 


 

View solution in original post

3 REPLIES 3
Reeza
Super User

Looks like GCHART doesn't recognize the format for some reason. 

 

I would probably just switch to SGPLOT - which you should do anyways - and use that instead. You get better graphics and it's easier to work with. You'll find a lot of old courses and tutorials still reference the SAS/GRAPH procedures since the language is almost 50 years old now. 

 

PROC sgplot DATA=work.Cars;

     VBAR MSRP/ stat=freq;

RUN;

 


@tgrandchamp wrote:

Greetings and Thanks in advance for the help. I feel like I am hung up on an issue that will be simple and obvious if someone can explain it to me. I am attempting to produce a simple bar graph from a data field that has been modified using a PROC format statement. However the bar graph is showing incorrectly (the format level range with the "high" designation is repeated numerous times and the frequencies for all ranges are off. Below is the an example of the code I am using with the example sashelp.cars dataset. along with the incorrect graphing output compared to the correct PROC FREQ output. How do I get my PROC GCHART output to match the PROC FREQ output?

 

PROC FORMAT;

VALUE Price low-20000 = '0-20K'

            20000<-35000 = '20K-35K'

            35000<-50000 = '35K-50k'

            50000<-high = '50K+';

RUN;

 

DATA work.cars;

     SET sashelp.cars;

     FORMAT MSRP Price.;

RUN;

 

PROC FREQ DATA=work.Cars;

     Tables MSRP / NOPERCENT NOCUM;

RUN;

 

PROC GCHART DATA=work.Cars;

     VBAR MSRP;

RUN;

QUIT;

 

 


 

ballardw
Super User

See if adding DISCRETE as an option to the GCHART vbar makes things look more as expected.

 

 
PROC GCHART DATA=work.Cars;
     VBAR MSRP /discrete;
RUN;
QUIT;

GCHART needs to be told explicitly not to treat numeric values as continuous. So without the DISCRETE option the algorithm splits the data into "ranges" based on internal rules about the range of data points. And after that the format is applied to the displayed axis variable. So funny things happen.

 

GraphGuy
Meteorite | Level 14

You need to use the 'discrete' option ...

 

PROC GCHART DATA=work.Cars;
VBAR MSRP / discrete;
RUN;

 

bar.png

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!

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.

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
  • 1164 views
  • 3 likes
  • 4 in conversation