BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Gil_
Quartz | Level 8
I have a col classified character $31
Here is example.
2018-04-03:11:26:45:573000000

I use
Data test;
Set test;
Day=substr(left(opendate),1,10);
Format day mmddyy10.;
Run;

I used that b4 the input to convert it.
1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14
data want;
   set have;
   day=INPUT(SUBSTR(left(opendate),1,10),yymmdd10.);
   format day mmddyy10.;
   run;
Thanks,
Suryakiran

View solution in original post

6 REPLIES 6
Reeza
Super User

INPUT() converts and you can try ANYDTDTM. for a datetime

 


@Gil_ wrote:
I have a col classified character $31
Here is example.
2018-04-03:11:26:45:573000000

I use
Data test;
Set test;
Day=substr(left(opendate),1,10);
Format day mmddyy10.;
Run;

I used that b4 the input to convert it.

 

Gil_
Quartz | Level 8
It converted to number here is code
Data test;
Set test;
Day_=input(day,ANYDTDTM.);
FORMAT DAY_ ANTDTDTM.;
RUN;

The output is this
1838332800
I would need it to look like 04/04/2018
Reeza
Super User

 You didn't apply the format correctly and since it's a date time, it creates a date time. You can display it as a date using DTDDMMYY10 or DTDATE9 or convert it using DATEPART() to get the date portion.


@Gil_ wrote:
It converted to number here is code
Data test;
Set test;
DayTime = input(day,ANYDTDTM.);
date = datepart(dayTime);

FORMAT DAY dtdate9. date ddmmyy10.;
RUN;

SuryaKiran
Meteorite | Level 14
data want;
   set have;
   day=INPUT(SUBSTR(left(opendate),1,10),yymmdd10.);
   format day mmddyy10.;
   run;
Thanks,
Suryakiran
Astounding
PROC Star

Even simpler (the FORMAT statement is still necessary):

 

day = input(opendate, yymmdd10.);

 

That assumes your character variable OPENDATE is left-hand-justified.

Gil_
Quartz | Level 8
Thank you

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 4876 views
  • 0 likes
  • 4 in conversation