BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

data have;

format app_date mmddyy10.;

date_mth = month(app_date);

date_mth1 = put(date_mth,Z2.);

run:

 

output
ID    app_date   date_mth
12    12/09/2018  12

65    06/15/2018  06

This works ok in the datastep

 

proc export outfile = "\\myserver\have.xlsb"

data= have

label

DBMS = excelcs replace;

Sheet = "Data";

Server = "myserver"

 

Output
LOAN_ID    APPLICATION DATE   DATE MONTH

 

run;

output example
ID     app_date      date_mth

12    12/9/2018       12

65    6/15/2018       6

 

The exported output correctly eliminates the leading zeroes in the app_date however I want to retain the leading zero in date_mth just as I did in the datastep using the put statement. So 6 should be 06 however it truncates during export.  How do I get it back?

2 REPLIES 2
Tom
Super User Tom
Super User

If you want to tell Excel how to format the data you probably need to use ODS EXCEL instead of PROC EXPORT.

Try this program.

data have ;
  input id app_date char_mth :$2. ;
  informat app_date mmddyy.;
  format app_date yymmdd10. ;
  date_mth = month(app_date);
cards;
12    12/09/2018  12
65    06/15/2018  06
;

proc export data=have 
  outfile='c:\downloads\test1.xlsx' replace
  dbms=xlsx
;
run;

ods excel file='c:\downloads\test2.xlsx' ;
proc print data=have ;
 var id ;
 var app_date / style(data)={tagattr='type:Date format:mm/dd/yyyy'}; 
 var char_mth / style(data)={tagattr='type:text'};
 var date_mth / style(data)={tagattr='format:00'} ;
run;
ods excel close;

image.png

Ksharp
Super User

Or adding a special character before it.

 

data have;

format app_date mmddyy10.;

date_mth = month(app_date);

date_mth1 = cats('09'x,put(date_mth,Z2.));

run:

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
  • 2195 views
  • 1 like
  • 3 in conversation