BookmarkSubscribeRSS Feed
dubya
Calcite | Level 5

Hello,

I'm creating a Time Series graph of air pollution over time. I have used the following code:

symbol1 interpol value=dot i=join;

axis1 label=(angle=90 "PAS: bPAHs on Particle Surface (ng/m3)");

proc gplot data=trip1;

by sample_ID;

plot pas_n*time /vaxis=axis1;

run;

quit;

My question: the "by" variable, sample_ID separates data by sampling ID.

An example: Sample_ID=0301BIt1

0301 = sampling location "terminal 3"

BIt1 = sampling area "truck" or "yard"

Does anyone have any suggestions as to how I would code the data so that when the title appears on the graph it inserts the sampling location and sampling area automatically instead of the 0301BIt1?

Or, is there a way to add a title to the graph that allows me to break down a sample ID from numbers into what it actually stands for, i.e.:

0301 = sampling location "terminal 3"

BIt1 = sampling area "truck" or "yard"

Thank-You!

1 REPLY 1
Cynthia_sas
SAS Super FREQ


Hi:

  There are a couple of different ways to do what you want.  1) Create a user-defined format for Sample_ID (shown in example 1); 2) Split Sample_ID into 2 variables -- one for Location and the other for Area and make a user-defined format for those new variables (shown in example 2). Note that I used a simple SUBSTR function to split Sample_ID -- this would only work if Sample_ID was ALWAYS 8 characters and Location was the first 4 characters and Area was the last 4 characters. If this is not the pattern for Sample_ID

 

Then, in Examples 3 and 4 (assuming you have SAS 9.2 or higher), I show a slightly different solution using PROC SGPANEL. PANELBY is a simple alternative to BY group processing, especially if you like the look of Tufte's "small multiples".

cynthia

** make several formats;
proc format;
  value $sampf '0301BIt1' = 'Location: Terminal 3 Area: Truck'
               '0301BIt2' = 'Location: Terminal 3 Area: Yard'
               '0302BIt1' = 'Location: Terminal 2 Area: Truck'
               '0302BIt2' = 'Location: Terminal 2 Area: Yard';
  
  value $Loc '0301' = 'Terminal 3'
             '0302' = 'Terminal 2';
                 
  value $area 'BIt1' = 'Truck'
              'BIt2' = 'Yard';
run;
  
** make some fake data (from another example, just added sample_id);
** note that there is Sample_ID;
** and then Sample_ID was split into Loc and Area --;
** making 2 new variables;
data trip1;
  length Sample_ID $8 Location Area $4;
  infile datalines;
  input monyy : monyy5. var1  Sample_ID $;
      
  Location = substr(Sample_ID,1,4);
  Area = substr(Sample_ID,5,4);
    
  format monyy monyy5. location $loc. area $area. sample_id $sampf32.;
  label month = 'Time'
        monyy = 'Time'
        var1 = 'Pas_N'
        Sample_ID = 'Sample ID';
return;
datalines;
JAN09  836   0301BIt1
FEB09  887   0301BIt1
MAR09  821   0301BIt1
APR09  844   0301BIt1
MAY09  898   0301BIt1
JUN09  923   0301BIt1
JAN09  764   0301BIt2
FEB09  786   0301BIt2
MAR09  793   0301BIt2
APR09  875   0301BIt2
MAY09  599   0301BIt2
JUN09  495   0301BIt2

JAN09  796   0302BIt1
FEB09  887   0302BIt1
MAR09  821   0302BIt1
APR09  844   0302BIt1
MAY09  898   0302BIt1
JUN09  812   0302BIt1
JAN09  754   0302BIt2
FEB09  786   0302BIt2
MAR09  773   0302BIt2
APR09  885   0302BIt2
MAY09  769   0302BIt2
JUN09  935   0302BIt2
;
RUN;
   
proc sort data=trip1 out=trip1;
by sample_id location area monyy;
run;
   
symbol1 value=dot i=join;
axis1 label=(angle=90 "PAS: bPAHs on Particle Surface (ng/m3)");
  
ods listing close;
ods html path='c:\temp' (url=none)
         file='Two_Methods.html' style=sasweb;
proc gplot data=trip1;
title '1) Use Sample_ID';
by sample_ID;
plot var1*monyy /vaxis=axis1;
run;
quit;
     
proc gplot data=trip1;
title '2) Use Location and Area';
by location area;
plot var1*monyy /vaxis=axis1;
run;
quit;
   
** Need SAS 9.2 or higher to use SGPANEL;
proc sgpanel data=trip1;
title '3) Use SGPANEL with Sample_ID';
panelby Sample_ID / novarname;
vline monyy / response=var1 markers;
colaxis values=('01jan09'd to '01jun09'd by month);
label var1='PAS: bPAHs on Particle Surface (ng/m3)';
format sample_id $sampf32.;
run;
     
proc sgpanel data=trip1;
title '4) Use SGPANEL with 2 Panel Vars';
panelby Location Area / novarname layout=lattice spacing=5;
vline monyy / response=var1 markers;
colaxis values=('01jan09'd to '01jun09'd by month);
label var1='PAS: bPAHs on Particle Surface (ng/m3)';
format location $loc15. area $area6.;
run;
    
ods html close;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1 reply
  • 747 views
  • 0 likes
  • 2 in conversation