I have been struggling with a data set I have been trying to make a pie chart with the means of 10 variables across all the States in the US. This implies I need 10 pie chart in all, representing the 10 variables.
Below is how I did my coding:
proc means data = final StackODSOutput mean maxdec = 2;
var No_Exercise Few_Fruit_Veg Obesity
High_Blood_Pres Smoker Diabetes
ods output summary = means;
proc print data = means(drop = _control_ NOBS);
pattern1 V=S c=vibg;
pattern2 v=s c=dabg;
pattern3 v=s c=mob;
pattern4 v=s c=day;
pattern5 v=s c=deoy;
pattern6 v=s c=grp;
pattern7 v=s c=gray;
pattern8 v=s c=beige;
pattern9 v=s c=indigo;
pattern10 v=s c=vliv;
/* Set the graphics environment */
goptions reset=all border cback=white
proc gchart data = means;
pie variable / sumvar = mean group = CHSI_State_Name;
But I keep getting this error message:
ERROR: A PIE chart for Variable was not possible because the sum variable Mean had one or more negative values.
Meanwhile I have no negative values.
Thanks for your help
Thank you very much for that. I had I copied earlier on, I mistakenly didn't post it.
This is how I created the FINAL data.
libname final "/home/augustinetarkom0/my_courses/";
FILENAME exam2 "/home/augustinetarkom0/my_courses/RISKFACTORSANDACCESSTOCARE.csv";
PROC IMPORT DATAFILE=exam2
* This is to printout the content of the raw data;
title "Listing of the content of the raw data";
PROC CONTENTS DATA=final.exam2;
* Here, I print the last 10 observations of the raw data that is uncleaned;
title "Listing of first 10 Observations of the Raw uncleaned data";
proc print data = final.exam2 (obs = 10);
* Cleaning the data;
array a(*) _numeric_;
do i=1 to dim(a);
if a(i) = -1111.1 then a(i) = .;
title "Listing the First 10 obs of the cleaned data";
proc print data = final (obs = 10);
The numbers are importing with some fuzz factor. i.e., they may appear as -1111.1, but actually contain a bit at the end that makes them appear to SAS as a number that is slightly off from -1111.1. You can read about why that happens by doing a web search for numeric precision.
I think the following will make the corrections that you attempted:
data final; set final.exam2; array a(*) _numeric_; do i=1 to dim(a); if fuzz(a(i)) eq -1111.1 then a(i) = .; end; drop i; run;
Art, CEO, AnalystFinder.com
@tarkom: You apparently have two additional numbers that contain negative values. If they also represent missing numbers, then you'd have to convert them as well.
I think the following will change those three sets of negative values to missing:
data final; set final.exam2; array a(*) _numeric_; do i=1 to dim(a); if fuzz(a(i)) in (-1111.1,-2222,-2222.2) then a(i) = .; end; drop i; run;
Art, CEO, AnalystFinder.com
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.