Discover More Tips and Techniques on This Blog

How to generate the month name from a numeric date value

Task: I have a SAS date and wanted to create a variable with the month name.
Here is how to do it......

Use MONNAMEw. format which is simple and easy.  You need to be using  SAS 9.X versions to make it work.

/*Use MONNAMEw. format*/
data month;
input date:mmddyy8.;
month_name=put(date,monname3.);
datalines;
01/15/04
02/29/04
07/04/04
08/18/04
12/31/04
;
run;

proc print;
run;

ERROR: The MS Excel table (worksheetname) has been opened for OUTPUT.

I happend to stumbleupon a post from SAS support blog regarding the ERROR message in the LOG file when trying to output a SAS dataset in the form of Excel sheet.


Direct link:


ERROR: The MS Excel table (worksheetname) has been opened for OUTPUT.

This table already exists, or there is a name conflict with an existing object. This table will not be replaced. This engine does not support the REPLACE option.
ERROR: Export unsuccessful. See SAS Log for details.

When you use the EXPORT procedure on an Excel workbook, the workbook might be corrupted and the following error message generated:

This problem can occur if a previous EXPORT procedure attempts to export a SAS data set in the workbook that does not contain any observations. The following example illustrates an export procedure on such a data set:

%macro blowup;

data a;
a=1;
stop;
run;


%do i=1 %to 2;

proc export data=a outfile="c:\temp\test.xls"
dbms=excel2000 replace;
run;


%end;
%mend;
%blowup;

The problem occurs because the SAS data set does not contain any data to export. As a result, a corrupted structure is created.

To circumvent the problem, do one of the following:

•Use the SQL procedure with a DROP TABLE statement to drop the empty data set before replacing it, as shown in the following example:

%macro blowup;

data a;
a=1;
stop;
run;


%do i=1 %to 2;

libname test excel 'c:\sastest\test2.xls';


proc sql;
drop table test.a;
quit;


libname test clear;


proc export data=a outfile="c:\sastest\test2.xls"
dbms=excel2000 replace;
run;


%end;
%mend;
%blowup;

Disclosure:

In the spirit of transparency and innovation, I want to share that some of the content on this blog is generated with the assistance of ChatGPT, an AI language model developed by OpenAI. While I use this tool to help brainstorm ideas and draft content, every post is carefully reviewed, edited, and personalized by me to ensure it aligns with my voice, values, and the needs of my readers. My goal is to provide you with accurate, valuable, and engaging content, and I believe that using AI as a creative aid helps achieve that. If you have any questions or feedback about this approach, feel free to reach out. Your trust and satisfaction are my top priorities.