DATA Step, Macro, Functions and more

Width specified for format invalid

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Width specified for format invalid

Greetings again all!

I'm using the ODS Tagset ExcelXP and ProcPrint multiple tables to multiple sheets in excel (well first to XML then Excel).  My problem is that when my dataset comes back blank no sheet is written, and my work book is considerably smaller.  To fix this problem I use the following MACRO (thnx SAS forum!):

%macro IFz1(data=&syslast) /des= 'if Zero make 1 obs' ;

data &data ;

   if nobs then stop ;

   output ;

   modify &data nobs=nobs ;

   stop ;

run ;

%mend  IFz1;

This inserts one observation when there are no observations.  The problem is that it can't add an observation when a date is involved; example:

proc sql;

         CREATE TABLE foo AS

         SELECT

               date1 format mmddyy11. AS date2,

          FROM foo2;

%IFz1 will then run but come back with ERROR: Width specified for format MMDDYY is invalid, when I comment out the "format mmddyy11." it works fine and inserts a blank observation.  I believe that my column "date1" in my example is a DateTime data type.  If I change the format to mmddyyyy the column says: "5at1946" and is a "custom" data type in excel. 

Has anyone encountered this before, and is there a work around?  I would love to know!

Loving the SAS community so far, I hope to contribute at some point Smiley Happy

Thanks again!


Accepted Solutions
Solution
‎08-13-2014 06:21 PM
Super User
Posts: 10,500

Re: Width specified for format invalid

According to the documentation for SAS 9.3 mmddyy only has a range of 2 to 10 allowed. Change the 11 to 10 and it should work.

View solution in original post


All Replies
Solution
‎08-13-2014 06:21 PM
Super User
Posts: 10,500

Re: Width specified for format invalid

According to the documentation for SAS 9.3 mmddyy only has a range of 2 to 10 allowed. Change the 11 to 10 and it should work.

Super User
Posts: 3,106

Re: Width specified for format invalid

If you check out the documentation:

http://support.sas.com/documentation/cdl/en/leforinforref/63324/HTML/default/viewer.htm#p1og22ny80wq...

You will see that the maximum length for the mmddyy format is 10, hence the error you are getting. Also specify a format in SQL like so: select date1 format = mmddyy10. as date2

Occasional Contributor
Posts: 18

Re: Width specified for format invalid

Magic!

Thanks all!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 1917 views
  • 3 likes
  • 3 in conversation