Data visualization with SAS programming

Unable to make a pie of 10 variables across all the States in US

Reply
Contributor
Posts: 32

Unable to make a pie of 10 variables across all the States in US

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

PROC Star
Posts: 8,114

Re: Unable to make a pie of 10 variables across all the States in US

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

 

Contributor
Posts: 32

Re: Unable to make a pie of 10 variables across all the States in US

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

PROC Star
Posts: 8,114

Re: Unable to make a pie of 10 variables across all the States in US

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

 

Super Contributor
Posts: 469

Re: Unable to make a pie of 10 variables across all the States in US

Check your negative values in Means dataset.

Capture.PNG 

Thanks,
Suryakiran
PROC Star
Posts: 8,114

Re: Unable to make a pie of 10 variables across all the States in US

Posted in reply to SuryaKiran

@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

 

Contributor
Posts: 32

Re: Unable to make a pie of 10 variables across all the States in US

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

 

I appreciate that.

 

Regards

Contributor
Posts: 32

Re: Unable to make a pie of 10 variables across all the States in US

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

Contributor
Posts: 32

Re: Unable to make a pie of 10 variables across all the States in US

Posted in reply to SuryaKiran

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.

Ask a Question
Discussion stats
  • 8 replies
  • 169 views
  • 0 likes
  • 3 in conversation