BookmarkSubscribeRSS Feed
tarkom
Obsidian | Level 7

Hi All,

 

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
     Uninsured Elderly_Medicare
     Prim_Care_Phys_Rate Dentist_Rate;
     
 class  CHSI_State_Name;
ods output summary = means;
run;

proc print data = means(drop = _control_ NOBS);
run;
*************;

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;
run;
 
 /* Set the graphics environment */
goptions reset=all border cback=white
         ctext=black htitle=12pt;


proc gchart data = means;
   pie variable / sumvar = mean group =  CHSI_State_Name;
run;        
quit;

 

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

8 REPLIES 8
art297
Opal | Level 21

You didn't show how you created the file FINAL but, if importing the data you attached and running PROC MEANS on it, there are numerous negative values.

 

Art, CEO, AnalystFinder.com

 

tarkom
Obsidian | Level 7

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
 DBMS=CSV
 OUT=final.exam2;
 GETNAMES=YES;
RUN;


* This is to printout the content of the raw data;
title "Listing of the content of the raw data";
PROC CONTENTS DATA=final.exam2;
RUN; 


* 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);
run;

 

* Cleaning the data;

data final;
set final.exam2;
 array a(*) _numeric_;
 do i=1 to dim(a);
 if a(i) = -1111.1  then a(i) = .;
 end;
 drop i;

title "Listing the First 10 obs of the cleaned data";
proc print data = final (obs = 10);
run;

 

Thank you

art297
Opal | Level 21

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

 

SuryaKiran
Meteorite | Level 14

Check your negative values in Means dataset.

Capture.PNG 

Thanks,
Suryakiran
art297
Opal | Level 21

@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

 

tarkom
Obsidian | Level 7

@art297Thank you very much. I am going to try that out right away. This sounds refreshing.

 

I appreciate that.

 

Regards

tarkom
Obsidian | Level 7

Hi @art297 Thanks for pointing out that. I get some pie charts. But I have to read the report to make sure what the -2222 means. I am unsure as to whether it is used as missing value.

 

I really do appreciate your input.

 

Kind Regards,

 

tarkom

tarkom
Obsidian | Level 7

Okay, Thank you all very much for your quick response.

 

That is the problem I have.

 

How can I make the pie chart if there is a mean value of negative in it. Is there anyway to go about that?

 

As always, I appreciate your responses.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1817 views
  • 0 likes
  • 3 in conversation