SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Char to Numeric with Date Format

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Char to Numeric with Date Format

Hello,

i have a field date_in with data type character with value for example '15.04.2014 10:15' (DD.MM.YYY HH:MM)

Target field date_out has numeric type.

Is there any SAS date format which match with this format?

or how i can deliver the date in above format?

I just tried some formats with input(date_in, format) but cannot find the wanted format result.

Thanks for your support in advance



Accepted Solutions
Solution
‎06-18-2014 01:50 PM
Respected Advisor
Posts: 3,124

Re: Char to Numeric with Date Format

There is no out-of box format for your requirement, except you have to make your own:

proc format;

     picture cus_dtm

           low -  high      =  '%0d.%0m.%Y %0h:%0M'

           (datatype=datetime);

run;

data _null_;

     old='15.04.2014 10:15';

     new=input(old,ANYDTDTM23.);

     put new=cus_dtm20.;

run;

View solution in original post


All Replies
Respected Advisor
Posts: 3,124

Re: Char to Numeric with Date Format

is this what you are after?

data _null_;

     old='15.04.2014 10:15';

     new=input(old,ANYDTDTM23.);

     put new=datetime23.;

run;

Contributor
Posts: 24

Re: Char to Numeric with Date Format

I need text '15.04.2014 10:15' from old in new as date in format DD.MM.YYY HH:MM

Super Contributor
Posts: 275

Re: Char to Numeric with Date Format


PROC FORMAT;
  picture dt low-high='%0d.%0m.%0Y %0H:%0M' (datatype=datetime);
RUN;


data _null_;

     old='15.04.2014 10:15';

     new=input(old,ANYDTDTM23.);

     put new=dt.;

run;

Solution
‎06-18-2014 01:50 PM
Respected Advisor
Posts: 3,124

Re: Char to Numeric with Date Format

There is no out-of box format for your requirement, except you have to make your own:

proc format;

     picture cus_dtm

           low -  high      =  '%0d.%0m.%Y %0h:%0M'

           (datatype=datetime);

run;

data _null_;

     old='15.04.2014 10:15';

     new=input(old,ANYDTDTM23.);

     put new=cus_dtm20.;

run;

Contributor
Posts: 24

Re: Char to Numeric with Date Format

Yes Smiley Happy Its working fine now. Thanks a lot.

Best Regards


Frequent Learner
Posts: 1

Re: Char to Numeric with Date Format

[ Edited ]

My current character value is stored as DD.MM.YYY HH:MM. when changing it to the numeric value.

 

data _null_;
old='15.04.2014 10:15';
new=input(old,ANYDTDTM23.);
put new=datetime23.;
run;

Moderator
Posts: 238

Re: Char to Numeric with Date Format

One further recommendation:

 

Store the format somewhere permanently, so it's always available, and you don't have to keep redefining it in each SAS session:

 

proc format library=corpdata.myfmts;
     picture cus_dtm
           low -  high      =  '%0d.%0m.%Y %0h:%0M'
           (datatype=datetime);
run;

options fmtsearch=(corpdata.myfmts),

data _null_;
     old='15.04.2014 10:15';
     new=input(old,ANYDTDTM23.);
     put new=cus_dtm20.;
run;
☑ This topic is SOLVED.

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

Discussion stats
  • 7 replies
  • 611 views
  • 3 likes
  • 5 in conversation