DATA Step, Macro, Functions and more

sysfunc to convert SAS date does not work

Reply
Contributor
Posts: 55

sysfunc to convert SAS date does not work

 Hi,

I'd like to convert the macro variable sasdate to date9. format, but I can't get this to work.

I get the message below and i don't know what this message means.

Anyone ?

Thanks very much !

 

21         %let sasdate=%sysfunc(intnx(year,%sysfunc(today()),0));
22         %let otherdate = %sysfunc(INPUTN(&sasdate., YYMMDD8.), date9.);
WARNING: Argument 1 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.

Super User
Posts: 5,826

Re: sysfunc to convert SAS date does not work

[ Edited ]
Posted in reply to Billybob73

Why don't you use the correct format in the first %sysfunc call?

Not sure why you need all this logic, why not 

%let otherdate = 01Jan%substr(&sysdate9,6,4);

untested...

Data never sleeps
Super User
Super User
Posts: 9,200

Re: sysfunc to convert SAS date does not work

Posted in reply to Billybob73

Why?  As:

%put %sysfunc(today(),date9.);

You only need to specify the format in the call...

Super User
Posts: 9,560

Re: sysfunc to convert SAS date does not work

[ Edited ]
Posted in reply to Billybob73

As soon as I see two or more %sysfunc's in a single line of code, I go data step:

data _null_;
sasdate = intnx('year',today(),0,'b');
call symput('otherdate',put(sasdate,date9.));
run;

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Super User
Posts: 7,847

Re: sysfunc to convert SAS date does not work

Posted in reply to Billybob73

Your first step is generating a raw date value. The number of days since 1/1/1960.

So the second step needs to use the PUTN() function to apply a format.

%let otherdate = %sysfunc(PUTN(&sasdate., date9.));

Or you could generate the value using YYMMDDn8. format to begin with.

%let sasdate=%sysfunc(intnx(year,%sysfunc(today()),0),yymmddn8);

Then your INPUTN() function call should work.

 

Ask a Question
Discussion stats
  • 4 replies
  • 80 views
  • 0 likes
  • 5 in conversation