Date format conversion issue

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

Date format conversion issue

This should be simple but googling it has not provided me with a solution. I am trying to convert my date variable: MM/DD/YYYY HH:MMSmiley FrustratedS of character format $19. (informat: $19.) into numeric date9. I've tried:

data want;

set have;

     format adm_dat date9.;

run;

Error: the format $date was not found or could not be loaded.

Similarly I've tried:

data want;

set have;

     date = input(adm_dat, date9.);

run;

More errors than I care to list.

What should I try next?


Accepted Solutions
Solution
‎04-02-2013 01:40 PM
Super Contributor
Posts: 1,636

Re: Date format conversion issue

Hi,

try:

data want;

  set have;

  date=input(substr(adm_dat,1,10),mmddyy10.);

format date date9.;

run;

View solution in original post


All Replies
Solution
‎04-02-2013 01:40 PM
Super Contributor
Posts: 1,636

Re: Date format conversion issue

Hi,

try:

data want;

  set have;

  date=input(substr(adm_dat,1,10),mmddyy10.);

format date date9.;

run;

Respected Advisor
Posts: 3,799

Re: Date format conversion issue

You're on the right track you just need the proper INFORMAT.

17         data _null_;
18            length adm_dat $19;
19            adm_dat = '04/02/2013 12:38:45';
20            date = input(adm_dat,mmddyy10.);
21            format date date9.;
22            put (_all_)(=);
23            run;

adm_dat=
04/02/2013 12:38:45 date=02APR2013
PROC Star
Posts: 7,468

Re: Date format conversion issue

or

data have;

  informat adm_dt $19.;

  input adm_dt &;

  cards;

03/30/2013 10:00:00

04/01/2013 08:00:00

;

data want;

  set have;

  format date date9.;

  date=datepart(input(adm_dt,anydtdtm19.));

run;

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 673 views
  • 6 likes
  • 4 in conversation