DATA Step, Macro, Functions and more

Changing the Date format

Reply
Frequent Contributor
Posts: 107

Changing the Date format

[ Edited ]

Hello all,

 

I have been having issues converting date ths is in yymmdd10. to ddmmyy10.

 

I have been trying this code

 

, input(LVRTEDAT,yymmdd10.) as LVRTEDAT format ddmmyy10.
, input(LVPURDAT,yymmdd10.) as LVPURDAT format ddmmyy10.

 

 

ERROR: INPUT function requires a character argument.
ERROR: Character expression requires a character format.
ERROR: INPUT function requires a character argument.
ERROR: Character expression requires a character format.

LVTREDAT is a variable pulling from sql which is in yymmdd10.

 

I have also tried the below code and coming up with the below error

 

format LVINPDAT ddmmyy10.;
format LVRTEDAT ddmmyy10.;
format LVPURDAT ddmmyy10.;

 

ERROR: CLI cursor fetch error: [Microsoft][SQL Server Native Client 11.0]Numeric value out of range

 

FULL ACTUAL CODE:

 

proc sql exec;
connect to odbc (&connectA);
create table pveh as
select
LVPOLNO
, LVVEHNO
, LVVEHPRM
, LVVEHPRC
, LV1SPR2A
, LVALWDRV
, LVPLNNO
, LVNCD
, LVRGDPRS
, LVBASEXS
, LVADDEXS
, input(LVINPDAT,yymmdd10.) as LVINPDAT format ddmmyy10.
, input(LVRTEDAT,yymmdd10.) as LVRTEDAT format ddmmyy10.
, input(LVPURDAT,yymmdd10.) as LVPURDAT format ddmmyy10.
, LVNCDPRO
, LVCVRTYP
, LVUSECDE
, LVINSVAL
, LVVEHMOD
, LVVEHBDY
, LVCHPFCT
, LVVEHYRL
, LV1SPR7P0
, LVANNMLG
, LVBRKCVR
, LVLGLPRO
, LV2SPR1A
, LVMOPCDE
from connection to odbc
(select * from OPENQUERY
(BETA,'
Select
*
from
budadm.pveh as A
where
a.lVpolno >= '&min'
and a.lVpolno <= '&max'
and a.lVamdno = 1
')A)B;
disconnect from odbc;
quit;
run;

 

Your help will be much appreciated. Thanks :-)

Super Contributor
Posts: 490

Re: Changing the Date format

Your code look fine.

Could you select some rows without formating from these columns and post them here?

Frequent Contributor
Posts: 107

Re: Changing the Date format

Here are the unformatted columns. They are in date9. format. changed the format in the input statement and that's not working either


Capture.JPG
Super Contributor
Posts: 490

Re: Changing the Date format

I do not understand your dates are already saved in which format  date9. or yymmdd10 ???

Frequent Contributor
Posts: 107

Re: Changing the Date format

Just tried the below code and not sure why I am ending up with the below error?

proc sql exec;
connect to odbc (&connectA);
create table pveh as
select *

from connection to odbc
(select * from OPENQUERY
(BETA,'
Select
*
from
budadm.pveh as A
where
a.lVpolno >= '&min'
and a.lVpolno <= '&max'
and a.lVamdno = 1
')A)B;
disconnect from odbc;
quit;
run;


ERROR: CLI cursor fetch error: [Microsoft][SQL Server Native Client 11.0]Numeric value out of range
Super User
Super User
Posts: 7,401

Re: Changing the Date format

Macro variables e.g. &min need to be within double quotes to be dereferenced, e.g.:

a.lVpolno >= "&min"

 

What is it your doing, it looks like your passing a query through to a database?  Until your familiar with doing such a thing, just select * from table, get the data back to SAS and then process it.  If you want a response on your original question, do the above, get the data to SAS, and then post of proc contents of the retrieved data, and example of what it looks like.  Its likely you will get ISO dates, or date/times back from the database.

Super User
Posts: 9,681

Re: Changing the Date format

a.lVpolno >= '&min'
and a.lVpolno <= '&max'

-->

a.lVpolno >= %unquote(%nrbquote('&min'))
and a.lVpolno <=%unquote(%nrbquote('&max'))
Occasional Contributor
Posts: 6

Re: Changing the Date format

Hi,

 

Try this way...

 

input(put(LVRTEDAT,10.),yymmdd10.)) as LVRTEDAT format ddmmyy10.
, input(put(LVPURDAT,10.),yymmdd10.)) as LVPURDAT format ddmmyy10.

 

Thanks,

Bharath

Frequent Contributor
Posts: 107

Re: Changing the Date format

Already tried that before. Din't work.
Super User
Posts: 5,083

Re: Changing the Date format

[ Edited ]

Have you tried simplifying the code:

 

,  LVINPDAT format ddmmyy10.

 

The variable already has the proper value, you just need to change the format.

 

Since you are getting a message about values out of range, it is conceivable that you have a date-time variable and need to extract the date part:

 

, datepart(lvinpdat) as lvinpdat format ddmmyy10.

Ask a Question
Discussion stats
  • 9 replies
  • 298 views
  • 0 likes
  • 6 in conversation