DATA Step, Macro, Functions and more

Changing a character date var to a real date var

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 142
Accepted Solution

Changing a character date var to a real date var

Hi,

I have a  character variable that has a date string in it, so its not a real date variable but I need to change it to one.  The values look like this.

Apr-01-2015

Apr-05-2015

Mar-05-2015

May-10-2015

I have been trying various of syntax and functions but I haven't been able to figure-out the right combination. This is what I have so far:

 

order_date_new2= input(compress(order_date,'-'), yymmdd8.);

Any help is appreciated!


Accepted Solutions
Solution
‎08-07-2015 09:23 AM
Frequent Contributor
Posts: 144

Re: Changing a character date var to a real date var

Hi,

The syntax that you have use is almost OK. The format yymmdd, as far as I know, need First the year, then month and last Day, if you have dates in that format, I'm sure that is better ways to do it, but I will use Date9

date_real=input(scan(order_date,2,'-')||scan(order_date,1,'-')||scan(order_date,3,'-'),date9.);

View solution in original post


All Replies
Solution
‎08-07-2015 09:23 AM
Frequent Contributor
Posts: 144

Re: Changing a character date var to a real date var

Hi,

The syntax that you have use is almost OK. The format yymmdd, as far as I know, need First the year, then month and last Day, if you have dates in that format, I'm sure that is better ways to do it, but I will use Date9

date_real=input(scan(order_date,2,'-')||scan(order_date,1,'-')||scan(order_date,3,'-'),date9.);

Frequent Contributor
Posts: 142

Re: Changing a character date var to a real date var

Perfect. Thanks!

Respected Advisor
Posts: 3,777

Re: Changing a character date var to a real date var

There is an INFORMAT that will work too.  Remember to RTM.

data _null_;
  
x = input('Apr-01-2015',anydtdte11.);
   put x= x=date9.;
  
run;

23         data _null_;
24            x = input('Apr-01-2015',anydtdte11.);
25            put x= x=date9.;
26            run;

x=20179 x=01APR2015
☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 240 views
  • 1 like
  • 3 in conversation