Help using Base SAS procedures

Unable to convert a number to a SAS Date.

Reply
Contributor
Posts: 66

Unable to convert a number to a SAS Date.

Hi...

I am trying to convert a number to a SAS Date YYMMDD8. I m using proc Sql; from Oracle table  to BASE SAS table.

Input(put(date,8.),yymmdd8.) as Descn_date,

I have around 80 columns and around 30 columns have date as number for e.g 20150306 and so

I m not able to convert it

Pls help me on this.

Super User
Posts: 1,069

Re: Unable to convert a number to a SAS Date.

could you please try this


put(Input(date,yymmdd8.),yymmdd8.) as Descn_date

Thanks,
Jag
Esteemed Advisor
Posts: 7,060

Re: Unable to convert a number to a SAS Date.

If your date field actually contains just numbers like (20151003) then your code should have worked. Does your log provide any clue?

Conversely, is there a chance they are really numbers represented as a string?

If so, you could use something like:

proc sql noprint;

  create table want as

    select Input(date,yymmdd8.) as Descn_date format=date9.

      from have

  ;

quit;

Esteemed Advisor
Esteemed Advisor
Posts: 6,977

Re: Unable to convert a number to a SAS Date.

Well, there are a few things here.  Firstly, by proc sql from oracle table, does this mean you are using pass through and executing statements on the Oracle server?  If so you probably wont be able to use SAS functions.  Also, the "date" from Oracle is different.

I would suggest that you start by extracting the data as it is to a SAS dataset:

proc sql;

     connect to oracle ...;

     create table TMP as

     select * from connection to oracle (

          select * from SCHEMA.YOU_TABLE);

     disconnect from oracle;

quit;

Now examine the data you have got back.  The dates can processed using normal SAS techniques:

data tmp;

     set tmp;

     new_date=input(substr(date,...),yymmdd8.);

run;

I don't have an Oracle server here so can't check any of the above, but that is what I think you are getting stuck on.

Ask a Question
Discussion stats
  • 3 replies
  • 306 views
  • 0 likes
  • 4 in conversation