BookmarkSubscribeRSS Feed
raivester
Quartz | Level 8

I am using the chunk of code below to produce 150 graphs (3 versions of a graph for each of the 50 states). Unfortunately states don't have nice clean values ranging form 1 to 50; the values jump around a bit to reflect state FIPs codes. This tidbit may or may not be relevant. Anyway, I would like each of the graphs to have the state in the graph title. I am having trouble figuring out how to make this happen. 

 

/*Make a line plot for each state (x50), part (x3).*/
ods listing close;
ods pdf style=seaside
   file="S:\Projects\output.pdf"  
   compress=0 ;      

symbol1 INTERPOL=JOIN;
symbol2 INTERPOL=JOIN;
proc gplot data=merged; 
	plot1 var1*year var2*year/ overlay legend=legend1;
	by part state;
run;
3 REPLIES 3
ballardw
Super User

The SAS function FIPNAME will create an uppercase value of the state name from a 2-digit FIPS code,

The FIPNAMEL will create mixed case state name from 2-digit FIPS code.

FIPSTATE function will return a two letter state abbreviation from a 2-digit FIPS code.

 

Examples from the documentation:

x=fipname(37);
put x;
 
NORTH CAROLINA
x=fipnamel(37);
put x;
 
North Carolina
x=fipstate(37);
put x;
 
NC

 

So a data step and one of the above functions will likely add a text value to use that new variable on the BY statement.

 

Or create a format for the existing STATE variable that shows the desired text for the value of State. Then associate that format with teh variable in the Procedure. The By line in the proc output will by default show Variablename = Formatted Value.

 

 

Reeza
Super User

Out of curiousity I tested this - mostly to see if you can use #byval as a parameter to a macro function. Didn't seem to work. 

 

proc sort data=sashelp.cars out=cars;;
by make;
run;



data cars2;
set cars;
by make;
if first.make then counter+1;
if counter in (3,7,14, 43) then counter+1;
state = fipnamel(counter);
run;


options nobyline;
title "My Graph Title Customized #byval1";

proc sgplot data=cars2 (obs=100);
by state notsorted;
scatter x=weight y=mpg_highway / group = type;
run;


options nobyline;
title "My Graph Title Customized %sysfunc(fipnamel(#byval1))";

proc sgplot data=cars2 (obs=100);
by counter;
scatter x=weight y=mpg_highway / group = type;
run;


sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 280 views
  • 2 likes
  • 3 in conversation