BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
BJM
Calcite | Level 5 BJM
Calcite | Level 5

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
6 REPLIES 6
AMSAS
SAS Super FREQ

SAS Date Constant : "01APR2020"d not "04/01/2020"d

See Example: Define Date, Time, and Datetime Values in Date Constants 

BJM
Calcite | Level 5 BJM
Calcite | Level 5
I continue to have issues - did I misunderstand?
Proc Format Library = Quarter; ** period formats ********************************************************;
Value Period (Multilabel) /* update and run every quarter */
'01APR2020'd=(mmddyy10.) - '30MAR2021'd=(mmddyy10.) = '1'
'01Jul2020'd=(mmddyy10.) - '30JUN2021'd=(mmddyy10.) = '2'
'01Oct2020'd=(mmddyy10.) - '30SEP2021'd=(mmddyy10.) = '3'
'01Jan2021'd=(mmddyy10.) - '31DEC2021'd=(mmddyy10.) = '4' ;
Run;
;
Value Period (Multilabel) /* update and run every quarter */
222 '01APR2020'd=(mmddyy10.) - '30MAR2021'd=(mmddyy10.) = '1'
-
22
76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a format name.
ERROR 76-322: Syntax error, statement will be ignored.
223 '01Jul2020'd=(mmddyy10.) - '30JUN2021'd=(mmddyy10.) = '2'
224 '01Oct2020'd=(mmddyy10.) - '30SEP2021'd=(mmddyy10.) = '3'
225 '01Jan2021'd=(mmddyy10.) - '31DEC2021'd=(mmddyy10.) = '4' ;
NOTE: The previous statement has been deleted.
226 R
PaigeMiller
Diamond | Level 26

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.

2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png

--
Paige Miller
BJM
Calcite | Level 5 BJM
Calcite | Level 5

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;

 

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
BJM
Calcite | Level 5 BJM
Calcite | Level 5
In the monstrosity of the program I created, in some cases, I want the start date of the period, in some I want the full range of the period, and in a few cases, I want the start date for one group and the end date for the other. I have macro variable for labels, and for data selection.
I am attempting to revise this so it is more explanatory and obvious; it took me something like 9 months to develop the original program and I want to get it revised before I retire.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 443 views
  • 1 like
  • 3 in conversation