Help using Base SAS procedures

Function truncating strings on return

New Contributor
Posts: 2

Function truncating strings on return

I have a sas program that is dealing with sas datasets and oracle database tables and am attempting to write a few functions to change between the two. I also wrote an oracle_intnx for using the intnx function with an oracle date that changes it to sas date, calls intnx, then converts it back to an oracle date. So the problem is it's doing the conversions fine, but then when I test it the return string is getting truncated somewhere. Anyway my code:


%let start_date='01-JAN-2014';

libname output "[path removed]";

proc fcmp outlib=output.funcs.funcs;

  function oracledate_to_sasdate(oracledate $);

    stringDate = substr(oracledate,2,2)||substr(oracledate,5,3)||substr(oracledate,9,4);

    return (input(stringDate,date9.));


  function sasdate_to_oracledate(sasdate) $;

    put sasdate;


    put test;

    return (test);



  function oracle_intnx(interval $,oracledate $,num) $;


    put sas_date;


    put new_date;

    toReturn = sasdate_to_oracledate(new_date);

    put toReturn;

    return (toReturn);




options cmplib=output.funcs;

data _null;


put a;




put outputs:







The first 4 make sense, the 4th is the put test in sasdate_to_oracledate and is exactly what I want. But when this is returned to oracle_intnx and immediately put it shows up truncated. Can someone explain why this is? Thanks.

Super User
Posts: 13,521

Re: Function truncating strings on return

Looks like a variation on a SAS text variable without a defined length defaulting to 8 characters

'21-JAN- is 8 characters in length.

I think the variable SAS_DATE in your Oracle_intnx is treated as character as the function sasdate_to_oracledate creates a string.

New Contributor
Posts: 2

Re: Function truncating strings on return

oh ok solved it. Just put a length statement on toReturn before assigning the results of the conversion to it. Seems dumb that it would work like that but I guess I'll just need to create explicit variables with explicit lengths rather than doing stuff all implicitly. Thanks.

Occasional Contributor
Posts: 5

Re: Function truncating strings on return

Because SAS is an interpretive 4GL language, it assumes the length of the largest return value is the present one.  I would bet the day value of 01 is trimmed and reduced to 1, which throws it off.  You could send it a day greater than 09 and it would most likely work.  AND, you have indeed found the solution: the LENGTH statement will 'type' the storage requirement of the variable. 

you might investigate the INPUT function and see if converting the incoming ORACLE date to a SAS date on the SELECT statement.

Ask a Question
Discussion stats
  • 3 replies
  • 1 like
  • 3 in conversation