Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reformatting Date Field

Status
Not open for further replies.

1cutedimple

Programmer
Feb 27, 2004
11
CA
Hi, I have a dataset w/ date fields and datetime fields and I need to it in a certain format in a text file (no dashes). I'm using the compress function but tt's giving me a syntax error and not sure how to fix it. Here is my code. Anyone tell me how to fix it?

libname a ...;
%let out_file = ...\temp_data_new.txt';
%let in_file = ...\temp_data_new.txt';

data _NULL_;
set a.temp_data;
file &out_file;
put TO_DT YYMMDD10.
FROM_DT YYMMDD10.
PERMSN_TS DATETIME18.
;
run;

data temp (keep = TO_DATE FROM_DATE);
file &in_file;
input TO_DT $1-10 FROM_DT $11-20
TO_DATE = compress(TO_DT,'-');
FROM_DATE = compress(FROM_DT,'-');
run;

proc sql;
create table a.tempdata as
(select TO_DATE, FROM_DATE from temp);
quit;
 
Can you give an example of the date (or datetime) you start with and the one you want/need?
Klaz
 
Hi Klaz..
I was able to figure out the date field, but for the datetime field it comes in as this: 01OCT04:00:00:00
but I need to have it like this: 20041001:00:00:00
(4 digit year, 2 digit month, 2 digit day)

Thanks!
 
Try this for the following:

Say var x is your datetime value:

Code:
y = put(datepart(x),yymmddn8.)||':'||put(timepart(x),time8.);

Var y has the text version of the time you want.

Let me know if you need some more work on this string. I hope that this helps you,
Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top