BookmarkSubscribeRSS Feed
tarkom
Obsidian | Level 7

Dear All,

 

I have been trying to make a map using MAPS in SAS studio, but it appears it is broken. I think an alternative is the MAPSGFK.US_COUNTIES, for which I am not familiar on its usage and I have been trying to make a map on US States based on the following quartiles. 

 

The code and data I used is below:

 

* Calling the into SAS and creating a permanent library for it; 
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 fuzz(a(i)) in (-1111.1,-2222,-2222.2)  then a(i) = .;
  end;
  drop i;
run;

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

 

* Quartiles Calculations;

title "Table 1";
title2 "Listing of Quartiles";

proc means data = final StackODSOutput  P25 P50 P75 nway;
var   No_Exercise Few_Fruit_Veg Obesity
     High_Blood_Pres Smoker Diabetes
     Uninsured Elderly_Medicare
     Prim_Care_Phys_Rate Dentist_Rate;
     
ods output summary = quart;
run;

proc print data = quart(rename = (P25 = Q1 P50 = Median P75 = Q3));
run;

 

* fill patterns for the map areas (gray-scale fills);
pattern1 v = s c = grayff;
pattern2 v = s c = grayda;
pattern3 v = s c = grayaa;
pattern4 v = s c = gray68;

 

proc GPROJECT data=mapsgfk.us_counties      
out=mystates   degrees eastlong latlong;  
id state; 
run;

 

Can anyone assist me on how to make the a US map with the QUARTILES calculated above?

 

Thank you very much

 

tarkom

46 REPLIES 46
Reeza
Super User

GPROJECT does not make a map, it changes the projection of the data from one type to another.

PROC GMAP makes the map. Did you post the correct code? Can you explain exactly what's 'broken'? You didn't include your data (and I don't want to run your code anyways) or log so not really sure what's not working at this point. Explain in detail please. 

 

You can find a lot of fully worked examples here and in the example section of PROC GMAP.

http://robslink.com/SAS/democd1/aaaindex.htm

 

 


@tarkom wrote:

Dear All,

 

I have been trying to make a map using MAPS in SAS studio, but it appears it is broken. I think an alternative is the MAPSGFK.US_COUNTIES, for which I am not familiar on its usage and I have been trying to make a map on US States based on the following quartiles. 

 

The code and data I used is below:

 

* Calling the into SAS and creating a permanent library for it; 
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 fuzz(a(i)) in (-1111.1,-2222,-2222.2)  then a(i) = .;
  end;
  drop i;
run;

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

 

* Quartiles Calculations;

title "Table 1";
title2 "Listing of Quartiles";

proc means data = final StackODSOutput  P25 P50 P75 nway;
var   No_Exercise Few_Fruit_Veg Obesity
     High_Blood_Pres Smoker Diabetes
     Uninsured Elderly_Medicare
     Prim_Care_Phys_Rate Dentist_Rate;
     
ods output summary = quart;
run;

proc print data = quart(rename = (P25 = Q1 P50 = Median P75 = Q3));
run;

 

* fill patterns for the map areas (gray-scale fills);
pattern1 v = s c = grayff;
pattern2 v = s c = grayda;
pattern3 v = s c = grayaa;
pattern4 v = s c = gray68;

 

proc GPROJECT data=mapsgfk.us_counties      
out=mystates   degrees eastlong latlong;  
id state; 
run;

 

Can anyone assist me on how to make the a US map with the QUARTILES calculated above?

 

Thank you very much

 

tarkom


 

tarkom
Obsidian | Level 7

@ReezaThank you for your response.

 

What is broken is the SAS installed US map data called the MAPS. What I can access now is the MAPSGFK.US_COUNTIES. The MAPS data set doesn't seem to be working any longer.

 

I an now trying to create a MAP of US States from the MAPSGFK.US_COUNTIES data set for the various levels of the Quartiles I have created. But I am finding it a bit difficult.

 

I am sorry about the data set but I attached it earlier on. 

 

Thanks for the link too.

Reeza
Super User

I don't think the Maps are supported anymore, just the GFK ones now. But they're better quality anyways. 

tarkom
Obsidian | Level 7

Alright @Reeza. Thanks very much.

ballardw
Super User

@tarkom wrote:

 

Can anyone assist me on how to make the a US map with the QUARTILES calculated above?

 

 


Why? Your quartile results contain no variable with any geographic information:

proc means data = final StackODSOutput  P25 P50 P75 nway;
var   No_Exercise Few_Fruit_Veg Obesity
     High_Blood_Pres Smoker Diabetes
     Uninsured Elderly_Medicare
     Prim_Care_Phys_Rate Dentist_Rate;

You likely are missing one or more CLASS variables with the geographic indicator(s) such as State and County or similar. If you have State and County as numeric values corresponding the state and county values in the mapsgfk.us_counties data set there would also be no need to project.

 

 

Also what type of map? for which quartiles? How do you want them to appear on the map? Since you are requesting 3 values and Gmap generally prefers to show one value per geographic location you have some additional work to decide what you want.

 

When I make maps for multiple topics I generally create a topic variable so that I can use BY group processing to create a separate map for each topic. Also the STACKODS output format is likely to poorer for mapping.

 

You might want to peruse some of the example from http://robslink.com/SAS/  There a number of different maps and data summarizations used (plus other types of graphs)

tarkom
Obsidian | Level 7

@ballardwThanks for your response.

 

The idea is to create a US map using the results from the Quartiles generated for each of the ten variables. The STATES will be colored using the following four coloring schemes based on the above quartiles (less than Q1, between Q1 and the Median, between the Median and Q3, and greater than Q3). For a given variable, if the Median value for a STATE is less than or equal to Q1, a light color is preferred. And at the other extreme, a darker color if the Median value of the STATE is greater than Q3. This is the idea that I want to use in generating that map.

 

Thank You once again.

ballardw
Super User

So you want to map your raw data, which has values for the stated variables and STATE level coloring. Don't use the counties map unless you want a very busy map, use the US_STATES set.

For your consideration:

data values;
   do state=1 to 56;
      med = round( 100*rand('uniform'),0.01);
      output;
   end;
run;


pattern1 v = s c = grayff;
pattern2 v = s c = grayda;
pattern3 v = s c = grayaa;
pattern4 v = s c = gray68;

proc gmap map=mapsgfk.us_states
          data=values
;
   id state;
   choro med /levels=4
              coutline=black
              cempty=black
   ;

run;
quit;

Note that the numeric values of STATE used are not what you might expect as the coding includes DC and protectorates such as Virgin Islands, Puerto Rico, Guam and some others I don't remember right now.

 

 

There is actually no reason to separately calculate the medians. The documentation of the Choro option Levels:

By default, an equal-distribution (quantizing) algorithm is used to determine each level.

which is basically the same as quartiles when using LEVELS=4.

If you do not specify patterns then the current ODS style gradient map values will assign lighter to darker colors.

 

If you don't like the appearance of the Alaska and Hawaii in geographic relationship there are a number of example programs around to create insets for those so the continental part of the US is the majority of the map with those two in different display areas.

 

 

 

What you describe would be a CHORO map statement with either MIDPOINTS specifying values that create the desired interval (likely not the easiest to implement) or a custom format to show the desired ranges

tarkom
Obsidian | Level 7

@ballardwI really do appreciate your input and assistance.

 

I am getting a fair idea now. What I am also thinking now is to see if there could be a way to format the quartiles from the data and earlier code I sent on the quartiles so that I can replace that with the raw values you created.

 

I think if I am able to create some kind of format for the quartiles, i.e,

low - Q1= "less than Q1"

Q1-Median = " Between Q1 and Median"

Median - Q3 = "Between Median and Q3"

Q3 - high = "Greater than Q3";

 

I think if I am able to get a format like this from the quartiles, then it can work out as expected.

 

Once again, I appreciate your input.

 

Regards,

Reeza
Super User

@tarkom PROC RANK with GROUPS=4 will give you the groups you want. But PROC GMAP does that automatically, which is what @ballardw was trying to explain. 

tarkom
Obsidian | Level 7

@ReezaSure...

That's right and I understood what @ballardw was trying to let me understand. But that appears to be raw data. But what I am expecting and trying to do is based on an actual data set. That is the only difference.

 

Thank you.

Reeza
Super User

@tarkom wrote:

@ReezaSure...

That's right and I understood what @ballardw was trying to let me understand. But that appears to be raw data. But what I am expecting and trying to do is based on an actual data set. That is the only difference.

 

Thank you.


What's the difference between raw data and an actual data set? He made data to illustrate the issue, that's all. Your data set is the same...

ballardw
Super User

@tarkom wrote:

@ballardwI really do appreciate your input and assistance.

 

I am getting a fair idea now. What I am also thinking now is to see if there could be a way to format the quartiles from the data and earlier code I sent on the quartiles so that I can replace that with the raw values you created.

 

I think if I am able to create some kind of format for the quartiles, i.e,

low - Q1= "less than Q1"

Q1-Median = " Between Q1 and Median"

Median - Q3 = "Between Median and Q3"

Q3 - high = "Greater than Q3";

 

I think if I am able to get a format like this from the quartiles, then it can work out as expected.

 

Once again, I appreciate your input.

 

Regards,


If you write your own legend statement and suppress the automatic legend (NOLEGEND option in the Choro statement) from Proc Gmap no format would be needed and no summaries. The legend would show the text you want and the color/marker assignments you use.

 

I suggest getting one map to work with desired appearance and then work on placing of Legend statement as the location information you need to supply will change with a different map appearance.

 

 

 

tarkom
Obsidian | Level 7

Alright...

 

Thanks for the help.

GraphGuy
Meteorite | Level 14

My first/simplistic try at plotting this was wrong - I deleted it so as not to confuse anyone with wrong code. Yep, even I make mistakes! 😉

 

[deleted code]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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