BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BETO
Fluorite | Level 6

Hi currently I've  A date formatted  like this 20080220 00:00:00... I tried doing a datepart to format it to  MMDDYY8.  SAS or Excel doesn't see it as date ... How can a  data step convert this to a date  that can used to query?  Thanks again for your assistance

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

I agree.  It depends upon what you are doing and from where.  If the value is coming into SAS as a character string, the following might connect the dots:

options datestyle=ymd;

data table_a;

  informat dt $20.;

  input dt;

  cards;

20080220 00:00:00

;

data want;

  set table_a;

  format want_dt date9.;

  want_dt=input(dt,anydtdte8.);

run;

View solution in original post

7 REPLIES 7
art297
Opal | Level 21

If the time part is irrelevant, anyhow, you could use the anydtdte informat to only read the first 8 digits.  e.g.:

options datestyle=ymd;

data have;

  informat dt anydtdte8.;

  format dt date9.;

  input dt;

  cards;

20080220 00:00:00

;

GeorgeSAS
Lapis Lazuli | Level 10

%put %sysfunc(putn(%sysfunc(timepart(%sysfunc(DATETIME()))),time8));

BETO
Fluorite | Level 6

The name of my table is Table_A  with  Date/Time for name of col with 20080220 00:00:00 . With the responses provided how do I connect the dots to format it to mmddyy8. ? And thanks again for your assitances

ballardw
Super User

Is this connecting to another database? There are some issues other than SAS formats that may need addressing if so.

art297
Opal | Level 21

I agree.  It depends upon what you are doing and from where.  If the value is coming into SAS as a character string, the following might connect the dots:

options datestyle=ymd;

data table_a;

  informat dt $20.;

  input dt;

  cards;

20080220 00:00:00

;

data want;

  set table_a;

  format want_dt date9.;

  want_dt=input(dt,anydtdte8.);

run;

BETO
Fluorite | Level 6

Hi Art,

The name of the table is "Table_A" which you make referance in your recomendation the column that has the 20080220 00:00:00 is name Date/Time  in your example where do I make referance to that column ?... Thanks again for your assitance

art297
Opal | Level 21

I referenced the column as having the name dt, thus you would just replace dt with the variable's actual name, and you would change the name want_dt to be the name of the new date variable that you want.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1229 views
  • 6 likes
  • 4 in conversation