The SAS Output Delivery System and reporting techniques

Remove leading zeros ODS output

Accepted Solution Solved
Reply
Regular Contributor
Posts: 180
Accepted Solution

Remove leading zeros ODS output

data want (keep= ID mydate);

set want1;

run;

OUTPUT

ID    mydate
12    09/16/2015
15    06/02/2013
16    10/06/2016

 

 

ODS TAGSETS.ExcelXP file= "c:/want,xml";

PROC REPORT DATA= want headskip split='*' wrap nowd

 

COLUMNS _all_;

 

DEFINE mydate / Display style(column)= { cellwidth=80pt just=right} "mydate";

run

 

I want to remove any leading zeros that may exist.  The desired output would be

OUTPUT

ID    mydate
12    9/16/2015
15    6/02/2013
16    10/6/2016

 

Would tagattr be required for something like this??

 

 


Accepted Solutions
Solution
‎03-29-2018 03:51 PM
Contributor
Posts: 61

Re: Remove leading zeros ODS output

You could try something like this on your "want1" dataset:

 

data a;
date="01jan2018"d;
newdate=catx('/',month(date),day(date),year(date));
format date mmddyys10.0;
run;

View solution in original post


All Replies
Solution
‎03-29-2018 03:51 PM
Contributor
Posts: 61

Re: Remove leading zeros ODS output

You could try something like this on your "want1" dataset:

 

data a;
date="01jan2018"d;
newdate=catx('/',month(date),day(date),year(date));
format date mmddyys10.0;
run;

SAS Super FREQ
Posts: 9,426

Re: Remove leading zeros ODS output

Posted in reply to mdavidson

Hi:

  In the interest of completeness, you can get the results you want, in TAGSETS.EXCELXP by using a PICTURE format without using TAGATTR, as shown in the program code below:

data want (keep= ID mydate);
  infile datalines;
  input ID mydate : mmddyy.;
  format mydate date9.;
datalines;
12 09/16/2015
15 06/02/2013
16 10/06/2016
;
run;
  

proc format;
   picture dfmt (default=10) other='%m/%d/%Y' (datatype=date);
run;

ods excel file='c:\temp\wantxlx.xlsx';
ODS TAGSETS.ExcelXP file= "c:\temp\want.xml"
    style=htmlblue;

PROC REPORT DATA= want split='*' nowd;
 column id mydate mydate=d1 mydate=d2;
 DEFINE mydate / Display  "mydate*tagattr*(will get default format)"
  style(column)= {tagattr="Format:m/d/yyyy;"  just=right} ;
 define d1 / display f=dfmt. 'd1*no tagattr*only picture format'
  style(column)= {just=right} ;
 define d2 / display f=dfmt. 'd2*with tagattr*and picture format'
  style(column)= {tagattr="Format:m/d/yyyy;"  just=right} ;

run;

ods tagsets.excelxp close;
ods excel close;

The hitch with TAGSETS.EXCELXP is that as you can see below -- without a format and even using TAGATTR, with TAGSETS.EXCELXP, the output uses the SAS format for the column:

 

no_lead_zero.png

But, you can achieve what you want without making a character variable using a PICTURE format (or using TAGATTR).

 

Cynthia

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 159 views
  • 2 likes
  • 3 in conversation