BookmarkSubscribeRSS Feed
Gick
Pyrite | Level 9

Gick_0-1683180658325.png

 

 

/* Creating the table */
data piechart;
  input slice $ Vente Age;
  datalines;
  A 35 12
  B 10 2
  C 22 22
  D 40 67
  ;
run;

/*Creating the pie chart */
proc sgplot data=piechart;
  pie slice=Age ;
run;

Hello,

I want to make a pie chart (in percentage).

Each sector takes the value of the Vente so that their sum can make 100%.

I tried this code but it doesn't work. Here is a picture of what I want.

 

Can someone help me please.

Gick.

 

12 REPLIES 12
ballardw
Super User

If you check the documentation for SGPLOT, such as here: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/p1x0rnjgnvfw20n1scpxlolgjeok.htm you will find that there is NO "pie" plot.

 

Proc SGPie makes pie-charts: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatproc/n11xqf2g2rxnmbn1pgk4rbl5vz80.htm

 

I think you may want

proc sgpie data=piechart;
  pie Age / response= age datalabelloc=inside;
run;

Doesn't work is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the "</>" to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "</>" icon or attached as text to show exactly what you have and that we can test code against.

Gick
Pyrite | Level 9
No output result.

I have this error message in the log. "ERROR: Procedure SGPIE not found."

Why this problem?

Can someone help me please.
Gick
SASKiwi
PROC Star

SGPIE is only available in SAS 9.4M6 or later. Run this to confirm your SAS version and maintenance level:

proc product_status;
run;

For earlier versions PROC GCHART with the PIE statement should work if you have SAS/GRAPH.

Gick
Pyrite | Level 9
I don't have SAS version 9.4M6.

Here is the log:
For Logiciel Base SAS ...
Custom version information: 9.4_M3
Image version information: 9.04.01M3P062415
For SAS/STAT ...
Custom version information: 14.1
For SAS/GRAPH ...
Custom version information: 9.4_M3
For SAS/ETS ...
Custom version information: 14.1
For SAS/AF ...
Custom version information: 9.4_M3
For SAS/IML ...
Custom version information: 14.1
For SAS/CONNECT ...
Custom version information: 9.4_M3
For High Performance Suite ...
Custom version information: 2.2_M4
For SAS/ACCESS Interface to PC Files ...
Custom version information: 9.4_M3
For SAS/ACCESS Interface to ODBC ...
Custom version information: 9.4_M3
Gick
Pyrite | Level 9
How to take into account the values of the age?
With a single slice variable, I have the pie chart fine. This graph is represented in relation to the distribution of slice whereas I want it to take into account the values of the age.

Does anyone have any idea how we can get back to my concern (original question)

Best regards,
Gick
Gick
Pyrite | Level 9

Here we deviate a little from what I am looking for.

The idea is to take into account information from the Age variable and assign it to each slice.

This code just gives me the pie chart of the variable slice.

 

THANKS.

I always try to meet my initial objective.

 

Gick

Ksharp
Super User
Why not make a new dataset and using the macro I suggested?



data have;
set piechart;
do i=1 to age;
output;
end;
run;
Gick
Pyrite | Level 9
Hello,
No, it doesn't. With the proposed code, the loop i goes from 1 to age. It is heavy.
You should know that the variable age has modalities of 20, 30, 10, etc.

If I had SAS version 9.4M6, the proc sgpie should resume to my concern I think.

I'm always open to suggestions.

Best regards,
Gick
Gick
Pyrite | Level 9
With Excel, I just have to calculate the sales percentage and then I make a pie chart using the slice variable as legend.

But on SAS, I'm having trouble doing that.

Can someone help me please

Best regards,
Gick
ballardw
Super User

@Gick wrote:
With Excel, I just have to calculate the sales percentage and then I make a pie chart using the slice variable as legend.

But on SAS, I'm having trouble doing that.

Can someone help me please

Best regards,
Gick

I feel your pain. But from the other side. I learned how to code and make charts in SAS years before Excel was written. then moved to a job that used Excel for everything. I got stuck making reports and was constantly going through the same steps manual of highlighting cells and defining series and options. Which from my SAS experience I should have been able to develop the code once and then use BY processing to make many similar charts.

 

You have not mentioned what environment you are running SAS with. It might be that you have the older SAS/Graph available. Run this code which will show all of the SAS modules you have licensed.

Proc setinit; run;

Then look in the Log. You should see something similar to the following: If your result includes SAS/Graph then you can use Proc GCHART with a Pie option.

Site number:  11111111.
Expiration:   30JAN2024.
Grace Period:  45 days (ending 15MAR2024).
Warning Period: 45 days (ending 29APR2024).
System birthday:   18MAY2017.
Operating System:   WX64_WKS.
Product expiration dates:
---Base SAS Software
      30JAN2024
---SAS/STAT
      30JAN2024
---SAS/GRAPH
      30JAN2024
---SAS/Secure 168-bit
      30JAN2024
---SAS/Secure Windows
      30JAN2024
---SAS Enterprise Guide
      30JAN2024
---SAS/ACCESS Interface to PC Files
      30MAY2062
---SAS/ACCESS Interface to ODBC
      30MAY2062
---SAS Workspace Server for Local Access
      30JAN2024
---High Performance Suite
      30JAN2024

The way the options are arranged for SAS/Graph, which was designed for pen-based plotters originally, means you will get to learn very different options for setting appearance than the Sgplot and newer procedures.

You will have to check the syntax for Proc Gchart. Check the examples in the online help.

SASKiwi
PROC Star

Follow the link I provided in my first post to PROC GCHART and the PIE statement.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 12 replies
  • 1694 views
  • 3 likes
  • 4 in conversation