DATA Step, Macro, Functions and more

Regarding the date conversion.

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Regarding the date conversion.

Dear Experts. 

 

I am facing an issue while converting the below date (given as example) to the date format yymmdd10. 

 

Input Date : Wed Feb 03 00:00:00 CET 2016

 

Output Date: 2016-02-03 (As Expected)

 

I tired to change the input date with ANYDTDTE informat (using the INPUT function as date is coming from macro variable)and then tried to change it to YYMMdd10. format but it did not work out. 

 

Regards,

Gulshan


Accepted Solutions
Solution
‎02-08-2016 04:21 AM
Trusted Advisor
Posts: 1,118

Re: Regarding the date conversion.

Hello Gulshan,

 

If you only need the date, please try this:

%let d=Wed Feb 03 00:00:00 CET 2016;

data _null_;
d=input(cats(scan("&d",3),scan("&d",2),scan("&d",-1)), date9.);
put d= yymmdd10.;
run;

If you need the full datetime information, I suggest this:

data _null_;
dt=input(cats(scan("&d",3),scan("&d",2),scan("&d",-1)||':'||scan("&d",4)), datetime.);
d=datepart(dt);
put dt= datetime19.;
put d= yymmdd10.;
run;

 

View solution in original post


All Replies
Super User
Posts: 19,851

Re: Regarding the date conversion.

What does not work mean?

 

Please post your code and log including any errors you received.

Solution
‎02-08-2016 04:21 AM
Trusted Advisor
Posts: 1,118

Re: Regarding the date conversion.

Hello Gulshan,

 

If you only need the date, please try this:

%let d=Wed Feb 03 00:00:00 CET 2016;

data _null_;
d=input(cats(scan("&d",3),scan("&d",2),scan("&d",-1)), date9.);
put d= yymmdd10.;
run;

If you need the full datetime information, I suggest this:

data _null_;
dt=input(cats(scan("&d",3),scan("&d",2),scan("&d",-1)||':'||scan("&d",4)), datetime.);
d=datepart(dt);
put dt= datetime19.;
put d= yymmdd10.;
run;

 

New Contributor
Posts: 3

Re: Regarding the date conversion.

Posted in reply to FreelanceReinhard

Hi 

 

 

 

 

Respected Advisor
Posts: 3,799

Re: Regarding the date conversion.

Perhaps you're not telling the whole story.

34         %put NOTE: &=sysvlong;
NOTE: SYSVLONG=9.04.01M3P062415
35         data _null_;
36            input str $40. @1 date & ANYDTDTE.;
37            format date YYMMdd10. /*worddate.*/;
38            put (_all_)(/=);
39            cards;


str=Wed Feb 03 00:00:00 CET 2016
date=2016-02-03
New Contributor
Posts: 3

Re: Regarding the date conversion.

Posted in reply to data_null__

Hi Data_null__, 

 

Thanks for the solution. 

 

Regards,

Gulshan

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 232 views
  • 0 likes
  • 4 in conversation