<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to depict quartals of the year on the x-axis in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806210#M317612</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; is it also possible to change the format of 2021Q1 to Q12021.&lt;/P&gt;
&lt;P&gt;I tried several ways but it isn't working.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;I tried using the format qyy7.; (this doesn't work at all)&lt;/LI&gt;
&lt;LI&gt;Used proc format this way:&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value qt '01jan2021'= "Q12021"
              '01apr2021'= "Q22021"
              '01jul2021'=   "Q32021"
              '01oct2021'= "Q42021"
              '01jan2022'= "Q12022"
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;when I plot the graph, only the first and last values a printed out correctly the other values show something like this &lt;STRONG&gt;22371, 22462, 22554&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Apr 2022 08:40:33 GMT</pubDate>
    <dc:creator>Anita_n</dc:creator>
    <dc:date>2022-04-06T08:40:33Z</dc:date>
    <item>
      <title>How to depict quarters of the year on the x-axis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806000#M317519</link>
      <description>&lt;P&gt;Dear all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data which looks like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="480"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="223"&gt;phase&lt;/TD&gt;
&lt;TD width="58"&gt;QI_2021&lt;/TD&gt;
&lt;TD width="58"&gt;QII_2021&lt;/TD&gt;
&lt;TD width="58"&gt;QIII_2021&lt;/TD&gt;
&lt;TD width="83"&gt;QI_2022&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;I&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;TD&gt;14&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;II&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;TD&gt;30&lt;/TD&gt;
&lt;TD&gt;66&lt;/TD&gt;
&lt;TD&gt;55&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;III&lt;/TD&gt;
&lt;TD&gt;60&lt;/TD&gt;
&lt;TD&gt;70&lt;/TD&gt;
&lt;TD&gt;78&lt;/TD&gt;
&lt;TD&gt;67&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;QI_2021 represents the months January, February and March (the first quarter 2021)&lt;/P&gt;
&lt;P&gt;QII_2021&amp;nbsp;represents the months April, May and June (the second quarter 2021 )&lt;/P&gt;
&lt;P&gt;QIII_2021 represents the months July, August and September (the third quarter 2021)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wish to make a plot which looks similar to this&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Anita_n_0-1649145796433.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70117i2676AF5C2D1A619C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Anita_n_0-1649145796433.png" alt="Anita_n_0-1649145796433.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The quarters should be on the x-axis. I was thinking of assigning the months of the year on the xaxis, my problem is how to let the line start from within jan, feb, march region for the first quarter (for example) which in this case will be QI_2021. Maybe someone has a good tip for me how I can do that.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 09:53:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806000#M317519</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-04-05T09:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to depict quartals of the year on the x-axis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806006#M317521</link>
      <description>&lt;P&gt;Maxim 19: Long Beats Wide. Do not keep data (timepoints) in structure (variable names).&lt;/P&gt;
&lt;P&gt;So we first create a transposed dataset with date values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm="09"x;
input phase $ QI_2021 QII_2021 QIII_2021 QI_2022;
datalines;
I	5	10	14	8
II	20	30	66	55
III	60	70	78	67
;

proc transpose
  data=have
  out=long1 (rename=(col1=patients))
;
by phase;
var Q:;
run;

data long2;
set long1;
year = input(scan(_name_,2,"_"),4.);
select (substr(scan(_name_,1,"_"),2));
  when ("I") m = 1;
  when ("II") m = 4;
  when ("III") m = 7;
  when ("IV") m = 10;
end;
qtr = mdy(m,1,year);
format qtr yyq7.;
drop _name_ m year;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The graphics procedures can then make use of the data in a quite simple way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods graphics / reset width=6.4in height=4.8in imagemap;

title "Patients Phase I-III";

proc sgplot data=long2;
label
  patients = "Patients"
  qtr = "Quarter"
;
vline qtr / response=patients group=phase;
yaxis grid;
run;

ods graphics / reset;
title "";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code was developed with the Diagram task in SAS Studio and then refined with a title.&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Unknown-1.png"&gt;&lt;img src="https://communities.sas.com/skins/images/FD87FC08D4682D208909D8781B6AAB09/responsive_peak/images/image_not_found.png" alt="Unknown-1.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 09:29:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806006#M317521</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-05T09:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to depict quartals of the year on the x-axis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806210#M317612</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; is it also possible to change the format of 2021Q1 to Q12021.&lt;/P&gt;
&lt;P&gt;I tried several ways but it isn't working.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;I tried using the format qyy7.; (this doesn't work at all)&lt;/LI&gt;
&lt;LI&gt;Used proc format this way:&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value qt '01jan2021'= "Q12021"
              '01apr2021'= "Q22021"
              '01jul2021'=   "Q32021"
              '01oct2021'= "Q42021"
              '01jan2022'= "Q12022"
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;when I plot the graph, only the first and last values a printed out correctly the other values show something like this &lt;STRONG&gt;22371, 22462, 22554&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 08:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806210#M317612</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-04-06T08:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to depict quartals of the year on the x-axis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806229#M317613</link>
      <description>&lt;P&gt;Roll your own picture format to display dates like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
picture myqtr (default=6)
  low-high='%q%Y' (datatype=date)
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I ran into problems using this format in the SGPLOT procedure. I posted a new question dealing with this:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/Graphics-Programming/Why-does-SGPLOT-not-use-a-custom-format-correctly/m-p/806228" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/Graphics-Programming/Why-does-SGPLOT-not-use-a-custom-format-correctly/m-p/806228&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 09:29:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806229#M317613</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-06T09:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to depict quartals of the year on the x-axis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806232#M317614</link>
      <description>&lt;P&gt;I had already tried that also, unfortunately it doesn't work either. I get something like %q%Y on the graph.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 09:41:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806232#M317614</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-04-06T09:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to depict quartals of the year on the x-axis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806234#M317615</link>
      <description>&lt;P&gt;Yep, that's exactly the problem I ran into, and that's why I posted my question. I am honestly baffled, and hope that someone can explain to us what's going on there. Right now, I actually consider this a bug in SGPLOT.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 09:45:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806234#M317615</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-06T09:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to depict quartals of the year on the x-axis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806235#M317616</link>
      <description>&lt;P&gt;Okay, thanks for that. I hope someone else can help!!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 09:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806235#M317616</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-04-06T09:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to depict quartals of the year on the x-axis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806238#M317618</link>
      <description>&lt;P&gt;I found it. The Graph Template Language (the "code" of the graphics fed to ODS which then makes pictures out of it) cannot dealt with the directives of the picture format for dates, times and datetimes. See &lt;A href="https://documentation.sas.com/doc/de/pgmsascdc/9.4_3.5/grstatgraph/p0mwk2su1mw8bnn1f6xonfde64h5.htm" target="_blank" rel="noopener"&gt;here&lt;/A&gt;&amp;nbsp;and &lt;A href="https://communities.sas.com/t5/Graphics-Programming/User-defined-Formats-in-PROC-SGPLOT-cannot-use-discrete-axis/td-p/447824" target="_blank" rel="noopener"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;But you can work around this by creating a new variable, and forcing the order in the graph based on the order in the dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long2;
set long1;
year = input(scan(_name_,2,"_"),4.);
select (substr(scan(_name_,1,"_"),2));
  when ("I") m = 1;
  when ("II") m = 4;
  when ("III") m = 7;
  when ("IV") m = 10;
end;
qtr = mdy(m,1,year);
format qtr yyq7.;
qtr1 = put(qtr,myqtr.);
drop _name_ m year;
run;

proc sgplot data=long2;
label
  patients = "Patients"
  qtr1 = "Quarter"
;
vline qtr1 / response=patients group=phase;
yaxis grid;
xaxis discreteorder=data;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Apr 2022 10:02:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806238#M317618</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-06T10:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to depict quartals of the year on the x-axis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806247#M317621</link>
      <description>&lt;P&gt;I tried that, this is what I get in the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
47   data long2;
48   set long1;
49   year = input(scan(_name_,2,"_"),4.);
50   select (substr(scan(_name_,1,"_"),2));
51     when ("I") m = 1;
52     when ("II") m = 4;
53     when ("III") m = 7;
54     when ("IV") m = 10;
55   end;
56   qtr = mdy(m,1,year);
57   format qtr yyq7.;
58   qtr1 = put(qtr,myqtr.);
                   &lt;FONT color="#FF0000"&gt; ------
                    48
ERROR 48-59: The format MYQTR was not found or could not be
             loaded.&lt;/FONT&gt;

59   drop _name_ m year;
60   run;

NOTE: The SAS System stopped processing this step because of
      errors.
&lt;FONT color="#00FF00"&gt;WARNING: The data set WORK.LONG2 may be incomplete.  When this
         step was stopped there were 0 observations and 4
         variables.
WARNING: Data set WORK.LONG2 was not replaced because this step
         was stopped.&lt;/FONT&gt;
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Apr 2022 10:40:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806247#M317621</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-04-06T10:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to depict quartals of the year on the x-axis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806248#M317622</link>
      <description>&lt;P&gt;Since I did not specify a permanent location in my PROC FORMAT code, you always have to run that code before you use the format. The format will be stored in a catalog in WORK and not be available in a new session.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 10:44:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806248#M317622</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-06T10:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to depict quartals of the year on the x-axis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806254#M317627</link>
      <description>&lt;P&gt;Yes, you are right. It was my mistake. It worked the only thing I added was a Q at the beginning of the high-low value to get the Q's at the front of results, like getting Q12021 instead of 12021. Thank you very much&lt;/P&gt;
&lt;P&gt;see code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
picture myqtr (default=6)
  low-high='&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Q&lt;/FONT&gt;&lt;/STRONG&gt;%q%Y' (datatype=date)
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Apr 2022 11:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-depict-quarters-of-the-year-on-the-x-axis/m-p/806254#M317627</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-04-06T11:56:15Z</dc:date>
    </item>
  </channel>
</rss>

