BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
einstein
Quartz | Level 8

Hi there,

 

I'm trying to create a line graph with multiple lines for each product by year and quarter.  To display the year and quarter together, I simply concatenated the two variables and created a new year_qtr variable.  However, as you can see in the attached graph, it looks awfully crowded.  Is there a way to simply show the year once for the four quarters, as opposed to for each quarter?  And I'd still like to show the quarterly data points, so simply using the year variable doesn't help with that.  Any help would be greatly appreciated!

 

Code as generated by SAS below, but truncated.

 

%_eg_conditional_dropds(WORK.SORTTempTableSorted);
SYMBOL1
INTERPOL=JOIN
HEIGHT=10pt
VALUE=NONE
LINE=1
WIDTH=2

CV = _STYLE_
;
SYMBOL2
INTERPOL=JOIN
HEIGHT=10pt
VALUE=NONE
LINE=1
WIDTH=2

CV = _STYLE_
;
SYMBOL3
INTERPOL=JOIN
HEIGHT=10pt
VALUE=NONE
LINE=1
WIDTH=2

CV = _STYLE_
;
Legend1
FRAME
;
Axis1
STYLE=1
WIDTH=1
MINOR=NONE
label=('Number of Prescriptions');


Axis2
STYLE=1
WIDTH=1
MINOR=NONE
label=('Year, Quarter');


TITLE;
TITLE1 "Number of Prescriptions by Year/Quarter";
FOOTNOTE;
FOOTNOTE1 "Source: XXX Data, 2005-2015";

 

PROC SQL;
CREATE VIEW WORK.SORTTempTableSorted AS
SELECT statecd, hcv_rc ,year_qtr,
SUM(num_presc) AS num_presc_SUM
FROM HCV.HCVX

GROUP BY statecd,hcv_rc,year_qtr
ORDER BY statecd,hcv_rc,year_qtr
;
QUIT;
Legend1 label=(color=black height=1 'HCV Drugs') cborder=black;
PROC GPLOT DATA = WORK.SORTTempTableSorted; 
PLOT num_presc_SUM * year_qtr =hcv_rc
/
VAXIS=AXIS1

HAXIS=AXIS2

FRAME LEGEND=LEGEND1
;BY statecd;

RUN; QUIT;
%_eg_conditional_dropds(WORK.SORTTempTableSorted);
TITLE; FOOTNOTE;
GOPTIONS RESET = SYMBOL;

 


SAS Graph.PNG
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

One way would be to create a custom format that only dislayed the year for the first quarter:

 

proc format;

value $Myyrqtr

'2011   Q01' = '2011 Q01'

'2011   Q02' = 'Q02'

'2011   Q03' = 'Q03'

'2011   Q04' = 'Q04'

etc. 

and add

Format year_qtr $Myyrqtr.;

to the gplot code.

 

Everything else I can think of involves creating actual date variables. Then you could use a format to display the quarter and either ANNOTATE to get the year value (GPLOT)

 

Or move over to using GTL, something similar to this: http://support.sas.com/kb/35/169.html again using actual dates, ignore the band, vector and scatter bits and use one Series statement with a GROUP variable.

View solution in original post

9 REPLIES 9
ballardw
Super User

One way would be to create a custom format that only dislayed the year for the first quarter:

 

proc format;

value $Myyrqtr

'2011   Q01' = '2011 Q01'

'2011   Q02' = 'Q02'

'2011   Q03' = 'Q03'

'2011   Q04' = 'Q04'

etc. 

and add

Format year_qtr $Myyrqtr.;

to the gplot code.

 

Everything else I can think of involves creating actual date variables. Then you could use a format to display the quarter and either ANNOTATE to get the year value (GPLOT)

 

Or move over to using GTL, something similar to this: http://support.sas.com/kb/35/169.html again using actual dates, ignore the band, vector and scatter bits and use one Series statement with a GROUP variable.

einstein
Quartz | Level 8

Just tried using a format statement but for some reason it will only display the year now. 😞

ballardw
Super User

which format did you use?

The example I created may not work with your data as I am not sure how many spaces (or other not visible) characters may have appeared in your actual data.

 

einstein
Quartz | Level 8

 

Nevermind!  It worked! You were right, there was an extra space in between the year and quarter I didn't account for.  Thank you so much!

Jay54
Meteorite | Level 14

This is relatively easy with SGPLOT.  Using YYQ4. format on X axis with date values, I get this graph.  The split is automatic.

Not sure I can get 'Q1' instead of '1', etc.  I will check.

 

YrQtr.png

ballardw
Super User

Maybe a custom format:

proc format library=work;
picture myqtr (default=7)   
low-high= '%Y Q%q' (datatype=date)
;
run; 

data junk;
   do date='05Jan2015'd, '10APR2015'd,'25JUL2015'd,'17OCT2015'd  ;
   output;
   end;
   format date myqtr.;
run;
einstein
Quartz | Level 8

I tried this but it wouldn't just show the year for the first quarter.  It shows the two digit year and then quarter (11Q1 11Q2, etc.).  Is there something else I need to specify in the proc sgplot for this to work?

einstein
Quartz | Level 8

Does this code not work if you move to proc sgplot?  I changed the code to proc sgplot and now this format doesn't work anymore.

einstein
Quartz | Level 8

ah, I used the values and values display option and that seemed to solve the problem.

 

Thanks everyone!

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
  • 9 replies
  • 2035 views
  • 0 likes
  • 3 in conversation