Reporting SAS VIYA CAS

Visualizing Credit Data: How to Create High-Quality PDF Maps in SAS Viya

This code is also available in: Deutsch Español
Difficulty Level
Beginner
Published on :
Simon

Expert Advice

Simon
Expert SAS et fondateur.

Exporting maps to PDF in SAS involves a bridge between Geospatial Processing (the map data) and Output Delivery (the PDF container). To get professional results, you must manage both the coordinate logic and the stylistic presentation.

Handling the Output Resolution
When sending maps to PDF, resolution and scaling matter. The EXTRACTSCALE option in your GRADLEGEND is an expert touch—it ensures the legend remains readable and proportional regardless of the PDF page size.
This SAS© program demonstrates how to generate a geographic map with credit scores and export it to a PDF document. It uses ODS PDF for output management and PROC SGMAP for map generation, including ESRI map services and choropleth mapping. Dummy data for states, plot data, and credit scores are created internally using DATA steps. ODS PDF is used to manage output to a PDF file, and PROC SGMAP creates the map using geospatial and response data.
Data Analysis

Type : CREATION_INTERNE


Examples use generated data (datalines) or SASHELP.

1 Code Block
ODS PDF / PROC SGMAP Data
Explanation :
This SAS code generates a choropleth map of the United States displaying average credit scores, then exports this map to PDF format. The necessary data is created internally using DATA steps. ODS PDF is used to manage output to a PDF file, and PROC SGMAP creates the map using geospatial and response data.
Copied!
1DATA work.states;
2 INFILE DATALINES dlm=',';
3 INPUT state $ state_fips $;
4 DATALINES;
5AL,01
6AK,02
7;
8RUN;
9 
10DATA work.plot_data;
11 INFILE DATALINES dlm=',';
12 INPUT long lat statename $;
13 DATALINES;
14-86.791130,33.491130,Alabama
15-147.859167,64.843611,Alaska
16;
17RUN;
18 
19DATA mycaslib.scoreperstate;
20 INFILE DATALINES dlm=',';
21 INPUT state $ _Score_;
22 DATALINES;
23AL,700
24AK,720
25;
26RUN;
27 
28ods pdf (id=SapphireStyle) style=Sapphire file='output.pdf';
29title 'Average Credit Score in Each State';
30footnote4 'Map only includes the lower 48 states in the United States';
31 
32PROC SGMAP mapdata=work.states
33 maprespdata=mycaslib.scoreperstate
34 plotdata=work.plot_data;
35 esrimap
36 url='http://services.arcgisonline.com/arcgis/rest/services/
37Canvas/World_Light_Gray_Base';
38 choromap _Score_ / mapid=state id=state_fips
39 density=1
40 numlevels=4
41 leveltype=none
42 colormodel=(sty greenyellow deepskyblue cornflowerblue beige)
43 name='choro';
44 text x=long y=lat text=statename /
45 textattrs=(size=6pt);
46 gradlegend 'choro' / title='Average Credit Score'
47 extractscale;
48RUN;
49ods pdf close;
50QUIT;
Pro Tip
The ODS PDF statement acts as a "wrapper." Everything executed between the ods pdf open and ods pdf close statements is captured and formatted into the document.
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.

Related Documentation

Aucune documentation spécifique pour cette catégorie.