I want to make a multi-label format, feeding in dates.
I am doing something incorrectly.
Proc Format Library = Quarter; ** date range (time period) formats **;
Value Period (Multilabel)
'04/01/2020'd - '03/31/2021'd = "1"
'07/01/2020'd - '06/30/2021'd = "2"
'10/01/2020'd - '09/30/2021'd = "3"
'01/01/2021'd - '12/31/2021'd = "4" ;
Run;
;
The log message I get:
Proc Format Library = Quarter;
137 Value Period (Multilabel)
138 '04/01/2020'd - '03/31/2021'd = "1"
ERROR: Invalid date/time/datetime constant '04/01/2020'd.
ERROR: ''04/01/2020'D' is not a numeric value.
139 '07/01/2020'd - '06/30/2021'd = "2"
140 '10/01/2020'd - '09/30/2021'd = "3"
141 '01/01/2021'd - '12/31/2021'd = "4" ;
NOTE: The previous statement has been deleted.
142 Run;
What suggestions do you have?
SAS Date Constant : "01APR2020"d not "04/01/2020"d
See Example: Define Date, Time, and Datetime Values in Date Constants
SAS Date Constant : "01APR2020"d not "04/01/2020"d
See Example: Define Date, Time, and Datetime Values in Date Constants
This isn't what @AMSAS said
You want
'01APR2020'd - '30MAR2021'd = '1'
or if I may be so bold as to recommend an improvement
'01APR2020'd - '30MAR2021'd = '01APR2020 - 30MAR2021'
so that when the format is used, everyone knows which 12 months this is referring to.
Please @BJM from now, show us the ENTIRE log for a PROC or DATA step that has an error, instead of selecting parts of the log to show us. Please copy the entire log for this PROC (or this DATA step) as text and paste it into the window that appears when you click on on the </> icon.
Hi Paige
OK. so, I did misunderstand.
The periods are numbered 1 - 4 which is why I have them labeled that.
The current program summarizes by each period separately and I have to regroup them during the program. If I can get the multilabel format to work correctly, I should be able to use Proc Summary with the multilabel format.
I am hoping to revise my program to run a quarterly report using the multilabel formats.
And, now it works:
228 Proc Format Library = Quarter;
229 Value Period (Multilabel)
230 '01APR2020'd - '30MAR2021'd='1'
231 '01Jul2020'd - '30JUN2021'd='2'
232 '01Oct2020'd - '30SEP2021'd='3'
233 '01Jan2021'd - '31DEC2021'd='4' ;
NOTE: Format PERIOD has been written to QUARTER.FORMATS.
234 Run;
@BJM wrote:
Hi Paige
OK. so, I did misunderstand.
The periods are numbered 1 - 4 which is why I have them labeled that.
The current program summarizes by each period separately and I have to regroup them during the program. If I can get the multilabel format to work correctly, I should be able to use Proc Summary with the multilabel format.
I am hoping to revise my program to run a quarterly report using the multilabel formats.
If it is the case in your company or university where EVERYONE understands that period 1 is 01APR2020 to 30MAR2021, then you can use the value of '1'. But usually that's not the case. One of the major benefits of custom formats is that you can make the format appear as something people will understand, such as '01APR2020-30MAR2021' which more understandable than '1'. And anyway, one of the ideas of designing output that will be clear and understandable to people is to label and format things clearly. To me '1' is not a clear format for this data.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.