Help using Base SAS procedures

How to convert 20080220 00:00:00 to MMDDYY8. format?

Accepted Solution Solved
Reply
Regular Contributor
Posts: 240
Accepted Solution

How to convert 20080220 00:00:00 to MMDDYY8. format?

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


Accepted Solutions
Solution
‎03-16-2012 07:06 PM
PROC Star
Posts: 7,366

How to convert 20080220 00:00:00 to MMDDYY8. format?

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


All Replies
PROC Star
Posts: 7,366

How to convert 20080220 00:00:00 to MMDDYY8. format?

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

;

Regular Contributor
Posts: 212

How to convert 20080220 00:00:00 to MMDDYY8. format?

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

Regular Contributor
Posts: 240

How to convert 20080220 00:00:00 to MMDDYY8. format?

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

Super User
Posts: 10,550

How to convert 20080220 00:00:00 to MMDDYY8. format?

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

Solution
‎03-16-2012 07:06 PM
PROC Star
Posts: 7,366

How to convert 20080220 00:00:00 to MMDDYY8. format?

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;

Regular Contributor
Posts: 240

How to convert 20080220 00:00:00 to MMDDYY8. format?

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

PROC Star
Posts: 7,366

How to convert 20080220 00:00:00 to MMDDYY8. format?

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.

🔒 This topic is solved and locked.

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

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