BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jlr337
Fluorite | Level 6

Hi!

I am using ODS excel and it is working great except for one formatting issue.  I have date and time fields that format correctly in excel when there is a value, but the formatting is not the same if the cells are blank.  This is causing a problem/extra step for the end user.  The user wants to enter data after review into the empty cells.  Below is an example. The first row had values and exported from sas correctly using proc report/ods excel. I entered the same values in the second row directly in Excel.  The formats should be mmddyy10 and hh:mm for all cells 

Users can modify the cells using number format in excel but I would like to be able to eliminate that step.

The formatting is maintained when using ods tagset.excelxp regardless of value or not but I'm trying to get away from using this because it require either me or the end user to have an added step of re-saving the file as .xlsx since the output is in .xml. (I get warnings when I open & modify an .xml document so I always re-save as .xlsx before sending to users-  I'm sure my end users would be annoyed by all warning messages if it was sent as is)  I'm trying to make the process as efficient, convenient as possible so I'm open to any suggestions 🙂

 

 

ods excel output formatting issue 06.21.2018.png

 

In my program I have tried to format the variables in the proc sql step as well as in the define column portion of the proc report but neither maintains the formatting. 

Example code:

proc sql;
create table pt_list_dtl as
select

a.HSP_ACCOUNT_ID

,a.pt_name_mrn
,b.cdate format mmddyy10.
,b.ctime format hhmm.
from ...
where...
;
quit;

options missing=' '; 

ods listing close;

ods excel file='...xlsx';

ods excel

options (...);

proc report data=pt_list_dtl;
where pt_name_mrn in (&pat);
column cdate ctime;
define cdate/display 'Date Collected' format=mmddyy10. style(column)={cellwidth=1.5in};
define ctime/display 'Time Collected' format=hhmm. style(column)={cellwidth=2in};
run;

I'm currently using:

sas eg version 06.21.2018.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@jlr337

Below code should apply a constant cell format within the range of your output.

data sample(drop=_:);
  length cdate ctime 8;
  _cdate=today();
  _ctime=time();
  do _i=1 to 5;
    cdate=_cdate+_i;
    ctime=_ctime+50*_i;
    if _i=3 then call missing(cdate, ctime);
    output;
  end;
  stop;
run;

options missing=' ';
ods listing close;
ods excel file='c:\temp\test.xlsx';
ods excel options(index='on' SHEET_NAME='text-string');
proc report data=sample;
  column cdate ctime;
  define cdate/display 'Date Collected' format=mmddyy10. style(column)={cellwidth=1.5in tagattr='format: mm/dd/yyyy'};
  define ctime/display 'Time Collected' format=hhmm.     style(column)={cellwidth=2in tagattr='format: hh:mm'};
run;
ods excel close;
ods listing;

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

@jlr337

Below code should apply a constant cell format within the range of your output.

data sample(drop=_:);
  length cdate ctime 8;
  _cdate=today();
  _ctime=time();
  do _i=1 to 5;
    cdate=_cdate+_i;
    ctime=_ctime+50*_i;
    if _i=3 then call missing(cdate, ctime);
    output;
  end;
  stop;
run;

options missing=' ';
ods listing close;
ods excel file='c:\temp\test.xlsx';
ods excel options(index='on' SHEET_NAME='text-string');
proc report data=sample;
  column cdate ctime;
  define cdate/display 'Date Collected' format=mmddyy10. style(column)={cellwidth=1.5in tagattr='format: mm/dd/yyyy'};
  define ctime/display 'Time Collected' format=hhmm.     style(column)={cellwidth=2in tagattr='format: hh:mm'};
run;
ods excel close;
ods listing;
jlr337
Fluorite | Level 6

This is awesome!!  I don't understand yet how it's working but it IS working 🙂  Thank you so much.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 3974 views
  • 1 like
  • 2 in conversation