See sample code under Full Code tab.
If you do not want to create your own format, you can obtain the same result by prepending 'Q' to the result of the QTR function. An example is shown under Full Code tab.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/* OUTLIB specifies the name of an output data set to which compiled */
/* subroutines and functions are written. The name of the function */
/* being created is QFMT. */
proc fcmp outlib=work.functions.smd;
function qfmt(date) $;
length yyq4 $4;
yyq4=put(date,yyq4.);
if substr(yyq4,3,1)='Q'
then return(substr(yyq4,3,2));
else return(yyq4);
endsub;
run;
/* Specifies one or more SAS data sets that contain compiler subroutines */
/* to include during program compilation. */
options cmplib=(work.functions);
/* Specify the name of the function created above as the label followed by */
/* parentheses. */
proc format;
value qfmt other=[qfmt()];
run;
/* The format is called on a PUT statement to output DATE variable */
data _null_;
do m=1 to 12;
date=mdy(m,1,2010);
put date=qfmt.;
end;
run;
/****************** Obtaining same result without creating a format ************/
data _null_;
do m=1 to 12;
date=mdy(m,1,2010);
qtr=cats('Q',qtr(date));
put qtr=;
end;
run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/* These are the results from both sets of code */ date=Q1 date=Q1 date=Q1 date=Q2 date=Q2 date=Q2 date=Q3 date=Q3 date=Q3 date=Q4 date=Q4 date=Q4
Type: | Sample |
Topic: | SAS Reference ==> Functions ==> Character ==> CATS SAS Reference ==> Functions ==> Date and Time ==> QTR SAS Reference ==> Procedures ==> FCMP |
Date Modified: | 2011-07-15 11:08:25 |
Date Created: | 2010-12-20 12:32:35 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | z/OS | 9.3 TS1M0 | |
Z64 | 9.3 TS1M0 | |||
Microsoft® Windows® for x64 | 9.3 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter Edition | 9.3 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise Edition | 9.3 TS1M0 | |||
Microsoft Windows Server 2003 Standard Edition | 9.3 TS1M0 | |||
Microsoft Windows Server 2003 for x64 | 9.3 TS1M0 | |||
Microsoft Windows Server 2008 | 9.3 TS1M0 | |||
Microsoft Windows Server 2008 for x64 | 9.3 TS1M0 | |||
Microsoft Windows XP Professional | 9.3 TS1M0 | |||
Windows 7 Enterprise 32 bit | 9.3 TS1M0 | |||
Windows 7 Enterprise x64 | 9.3 TS1M0 | |||
Windows 7 Home Premium 32 bit | 9.3 TS1M0 | |||
Windows 7 Home Premium x64 | 9.3 TS1M0 | |||
Windows 7 Professional 32 bit | 9.3 TS1M0 | |||
Windows 7 Professional x64 | 9.3 TS1M0 | |||
Windows 7 Ultimate 32 bit | 9.3 TS1M0 | |||
Windows 7 Ultimate x64 | 9.3 TS1M0 | |||
Windows Vista | 9.3 TS1M0 | |||
Windows Vista for x64 | 9.3 TS1M0 | |||
64-bit Enabled AIX | 9.3 TS1M0 | |||
64-bit Enabled HP-UX | 9.3 TS1M0 | |||
64-bit Enabled Solaris | 9.3 TS1M0 | |||
HP-UX IPF | 9.3 TS1M0 | |||
Linux | 9.3 TS1M0 | |||
Linux for x64 | 9.3 TS1M0 | |||
Solaris for x64 | 9.3 TS1M0 |