BookmarkSubscribeRSS Feed
munitech4u
Quartz | Level 8

I have 3 columns in a dataset:

 

Latitude    Logitude    Phone

-89.2132      179.9323       A

34.1231       -85.123        B

23.45           -34.23         A

.....

 

 

It is a customer level data, where phone category can be A or B, I want to plot these categories over the Latitude and Logitude data in SAS, where A and B can take 2 different colors.

8 REPLIES 8
ballardw
Super User

Is there supposed to be a map involved?

What units are those latitude and longititude values supposed to be in? Latitude typically uses degrees with a range of -90 to 90 and longitude -180 to 180 degrees.

munitech4u
Quartz | Level 8
Map may not be necessary, but will be great if, we can have it. Yes, they are in degrees as you specified
BrunoMueller
SAS Super FREQ

Hi

 

with SAS/GRAPH you will get libraries named MAPS and MAPSGFK using the provided data and ODS GRAPHICS you can create maps. See the attachment for the example.

 

Here is an example:

 

/*
 * create the map data
 * use the resolution var to have less data points
 * create a new ID var for drawing the map
 */ 
data map_data;
  length id_c $ 32;
  set mapsgfk.europe;
  where
    resolution <= 3
  ;
  id_c = catx("_", id, segment);
run;

/*
 * create the data for locations
 * NOTE: use a different name for the latitude and longitude variables
 */
data locations;
  infile cards;
  input
    lat2
    Long2
    Phone $
  ;
cards;
50.598726 9.450487 A
52.201658 -1.730536 B
;

/*
 * concat the two data sets
 */
data plotdata;
  set map_data locations;
run;
 

/*
 * draw the map using SGPLOT
 * the POLYGON will draw the map
 * the SCATTER will plot data points
 */
ods graphics / width=1600 height=1200 ;

proc sgplot data=plotdata  ;
  styleattrs
    datasymbols=(diamondFilled squareFilled)
  ; 
  polygon x=long y=lat id=id_c / group=id fill  outline name="map";

  scatter x=long2 y=lat2 / group=Phone markerattrs=(size=15) name="loc";
  keylegend "loc";
  xaxis display=none;
  yaxis display=none;
run;

Bruno


map.png
munitech4u
Quartz | Level 8
I have about 1 million observation, how can i make it more visible friendly?
Rick_SAS
SAS Super FREQ

If you have overplotting, you can use transparency to attempt to reduce overplotting:

scatter x=long2 y=lat2 / group=Phone name="loc" transparency=0.9;

 If you have millions of points, you might also consider plotting the density of the data, rather than individual markers. You can use PROC KDE or check out the hexagonal binning macro that can create a density map.

munitech4u
Quartz | Level 8

I tried the transparency option as well. But the graph looks really bad.


map.jpg
BrunoMueller
SAS Super FREQ

Hi

 

I would make the marker size smaller.

 

Some questions:

Please explain, what the viewer of the graph should be able to read out of this graph?

Do many points have the same coordinates, for instance based on the ZIP code?

 

Bruno

munitech4u
Quartz | Level 8
I tried reducing the marker size, but I am not able to distinguish the 2 cases. How can I make the 2 cases visible and more bigger? I am fine, even if i don't include the map, just the scales of latitude and longitude

For your questions:
1. I want to see the density of both the cases across the longitude and latitude.
2. About the 95% of the points have different coordinates. 5% might be same.

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
  • 8 replies
  • 2215 views
  • 2 likes
  • 4 in conversation