gpfrepo
gpfrepo

Reputation: 13

output format sas function

Is there a way to define the format in which the output of a function has to be returned?

For example if I define this function

proc fcmp outlib=WORK.funcs.Dates;
   function mytoday();
         return (today());
   endsub;
RUN;
OPTIONS APPEND=(cmplib=WORK.FUNCS);

And then I use it in a data step...

data test;
  a=today();
  b=mytoday();
run;

I get BEST12. format.

   a            b   
 20485       20485   

I have to explicity set the format this way:

data test;
  format a b yymmdd10.;
  a=today();
  b=mytoday();
run;    

   a            b   
2016-02-01   2016-02-01

I guess the answer is NO. But I want to be sure.

Thanks

Upvotes: 1

Views: 68

Answers (1)

Tom
Tom

Reputation: 51621

You are right, you cannot attach a format to the output of a function.

You could instead create a macro that would generated the assignment statement and the format statement.

%macro mytoday(varname);
  &varname = today();
  format &varname date9.;
%mend mytoday;
data test;
   %mytoday(b)
run;

Upvotes: 1

Related Questions