BookmarkSubscribeRSS Feed
tarkom
Obsidian | Level 7

@ReezaAlright. Will give that a shot to see what I get.

Thanks

tarkom
Obsidian | Level 7

@Reeza @GraphGuy @ballardw 

This is what I did recently, but it was just a map for Florida and with just one variable. I created a format for the variable No_Exercise and I fed that on the map. That is why I was thinking I could generate a map for the US states again for the variables based on the quartiles I worked on by creating some sort of format just like I did for the single variable case for Florida map. But I still seem to be struggling with it though the work was due yesterday, I still want to learn. 

This is the previous code. I used the same data set I uploaded earlier on:

 

proc gproject data=mapsgfk.us_counties out=florida degrees eastlong latlong;
where state eq 12; /*Get Florida information*/
id state;
run;

proc format; /*Make categories for No_Exercise numbers*/
value inter .='No data'
low- 20 = 'less than 20'
20.1 - 25 = '20.1 - 25'
25.1 - 30 = '25.1 - 30'
30.1 - 35 = '30.1 - 35'
35.1 - high = 'higher than 35';
run;

pattern1 v=s c=CX90B0D9;
pattern2 v=s c=CX6E86A6;/*light greenish blue*/
pattern3 v=s c=CX4C5D73;/* moderate greenish blue*/
pattern4 v=s c=CX2A3440; /*dark greenish blue*/
pattern5 v=s c=CX121519;

proc gmap data=florida1(rename=(County_FIPS_Code = county)) map=florida;
id county;
choro No_Exercise / discrete;
format No_Exercise inter.; /*Break up into groups*/
note 'Florida with No_Exercise'; /*Title*/
run;
quit;

 

Thanks

GraphGuy
Meteorite | Level 14

You're wanting to create state quartile maps?...

 

Several years back, the levels= option of proc gmap was enhanced to perform quantile binning - you can use levels=4 to do quartiles (levels would be quintiles, etc).

 

Since your data has multiple obsns per state, I use proc sql to first calculate the average value per state (you might want to so something even more sophisticated - for example if the obsns are by county, you might weight them by the county population). 

 

Also a value of -1111.11 appears to represent "missing data"(?) - therefore I eliminate those values.

 

PROC IMPORT DATAFILE="RISKFACTORSANDACCESSTOCARE.csv"
 DBMS=CSV OUT=exam2 (rename=(state_fips_code=state));
 GETNAMES=YES;
RUN;

/* -1111.1 appears to represent 'missing' values, so get rid of those obsns */
data exam2; set exam2 (where=(No_Exercise>0));
run;

proc sql noprint;
create table exam2_summarized as
select unique state, avg(No_Exercise) as No_Exercise_avg
from exam2
group by state;
quit; run;

legend1 label=none position=top shape=bar(.15in,.15in);

title1 ls=1.5 "Average 'No Exercise' by State";
proc gmap data=exam2_summarized map=maps.us all;
format No_Exercise_avg comma8.2;
id state;
choro No_Exercise_avg / 
 cdefault=cornsilk /* states with no data */
 levels=4 /* quartiles */
 legend=legend1;
run;

 

And here is the output:

 

map2.png

 

tarkom
Obsidian | Level 7

@GraphGuyThat seems so cool. I made some changes and incorporate all the 10 variables hence creating 10 different maps for all 10 variables. When I compare it to the quartiles I created initially and with the 4 categories I was expecting, I see that under each 4 levels created in the map by using the levels=4, it captures each value for the quartiles computed manually. This seems cool now.

Thanks very much

tarkom
Obsidian | Level 7

@GraphGuyIndeed, I'm really learning a lot here right now. But another thing I will like to learn in addition is that can we or is there a way to format the various categories created under the map to some specific giving names? Fro instance, in the map you attached, we have the first category to be 17.88-21.72, Is there a way to rename this and other categories to say Less than Q1 for the first category (17.88-21.72)?

Thanks for the learning experience

GraphGuy
Meteorite | Level 14

You can hardcode the text you want at each of the legend ticks, via the legend statement...

 

legend1 label=none position=top shape=bar(.15in,.15in) value=(t=1 'Less than Q1');

 

tarkom
Obsidian | Level 7

This is just perfect @GraphGuy. Thanks so much. I really get it now. Supper good.

 

I do appreciate this.

 

Kind Regards,

tarkom
Obsidian | Level 7

@GraphGuy @Reeza @ballardw

 

I really do appreciate your input. But I guess I will continue asking for me until I fully appreciate SAS.

 

I previous worked on pie chart for each states with the means of these same 10 variables. I am not sure what I had is what I am supposed to get.

this is the code I used in the generating the charts and the chart is attached as well. Any inputs on the graphs? 

For example, with the variable "Dentist" I see District occupying 102.80 and the remaining of the chart has Other 1775.69. I didn't understand where the Other came from. In my mind, I was expecting all states represent like what the variable "Early_Medicare" almost did.

GraphGuy
Meteorite | Level 14

Were you creating a pie chart with each slice representing a county? In a Ghart pie chart, by default if a slice is less than a certain percent of the pie, it goes into the 'Other' slice. I think you can use an option (maybe 'other=0' ?) to make it so that each county has a slice, no matter how small the slice. (I'm not sure this is a 'good' way to visualize the data, but at least it will give you a more clear picture of what's going on in your pie chart.)

 

tarkom
Obsidian | Level 7

@GraphGuyYou are so right. Pie chart in this case is not a good representation. That option you gave actually worked and it was observed that Text boundaries for the pie/donut slices overlap

Thank you very much once again.

tarkom
Obsidian | Level 7

@GraphGuy @Reeza @ballardw...As always, thank you very much for making my  learning of SAS more interesting and with fun.

 

I am still trying harder to interrogate graph to the core...Now I have all ten variables plotted on the map. But one thing I still think can be done but couldn't figure out is the maps all seem to have the same color scheme and hence, very difficult to study the maps individually. If one do not pay careful attention, it will appear the map has just been repeated 10 times, but each map represent a specific variable. So my problem is, can different colors be given to each variable on each map?

 

Also, against each variable on the map comes with the name of the statistic used, that is mean in bracket, can this name be suppressed? 

Here is the code and output to that effect.

 

proc gproject data=mapsgfk.us_states out=mymap degrees eastlong latlong;
where state eq state;
id state;
run;

/* Assign a color to each map type */
pattern1 v=s c=CX90B0D9;
pattern2 v=s c=CX6E86A6;/*light greenish blue*/
pattern3 v=s c=CX4C5D73;/* moderate greenish blue*/
pattern4 v=s c=CX2A3440; /*dark greenish blue*/
pattern5 v=s c=CX121519;

legend1 label = (position = top justify = center
 font = 'albany amt/bold' height = 4pct)
position = top shape = bar(.15in,.15in)
value = (t = 1 'Less than Q1' t = 2 'Between Q1 and Median'
 t = 3 'Between Median and Q3' t = 4 'Greater than Q3');

proc gmap data = final(rename = (State_FIPS_Code = State)) map = mymap;
id State;
choro   No_Exercise Few_Fruit_Veg Obesity
     High_Blood_Pres Smoker Diabetes
     Uninsured Elderly_Medicare
     Prim_Care_Phys_Rate Dentist_Rate /
     levels = 4  legend = legend1 statistic = mean;
     
/*Break up into groups*/
note "Map With all 10 Variables"; /*Title*/
run;
quit;

GraphGuy
Meteorite | Level 14

If you use the statistic= option, you get the '(Mean)' label appended to the title. I don't think there is a way to override it.

 

I would recommend using Proc Sql to pre-calculate the statistic, and then not use the statistic= option in gmap (see the example I previously posted).

 

tarkom
Obsidian | Level 7

@GraphGuyAlright, I will do that for the proc sql. One thing I noticed with the proc sql was that the map output came twice, any reason for that?

And how do I incorporate different colors for each variable?

GraphGuy
Meteorite | Level 14

Instead of using 1 Proc Gmap, with all the variables on the choro statement, use a separate Proc Gmap for each one ... and then you can use different pattern statements for each Gmap.

 

tarkom
Obsidian | Level 7

@GraphGuySounds good. I actually thought I could do all at once. But I will do them individually.

 

Thank you very much

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 46 replies
  • 3801 views
  • 3 likes
  • 4 in conversation