DATA Step, Macro, Functions and more

macro error using inputn

Occasional Contributor
Posts: 16

macro error using inputn

Hi all,

I have the below:

%let date1='08/01/2013'

%LET xDate = inputn(%sysfunc(compress(&date1,"")),"yyyymm.");

However, xDate never gets the changed date format (yyyymm) based on the above. 

Super User
Posts: 10,239

Re: macro error using inputn

Posted in reply to sasboy007

First of all, your code has a syntax error (missing the semicolon after the %let)

Second, inputn is a data step function that will not work on its own in a macro statement.

Third, yyyymm is not a valid SAS format, but yymm is.

to make it simple, use a data step:

%let date1=08/01/2013;

data _null_;

datenew = put(input("&date1",mmddyy8.),yymm.);

call symput("xdate",datenew);


%put "&xdate";

Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Super User
Posts: 9,599

Re: macro error using inputn

Posted in reply to KurtBremser

Just to add to that, why not keep the date in a parameter dataset and use it from there, e.g. joining it on.  It avoids that whole nasty macro variable processing of converting string to date and back again.

Super User
Posts: 13,542

Re: macro error using inputn

Or use a proper date literal such as '01AUG3013'd

Super User
Super User
Posts: 8,097

Re: macro error using inputn

Posted in reply to sasboy007

I think that your real error is not specifying a length on your INFORMAT.  You also have messed up values because of extra quotes. Macro variables are always text strings, so unless you want to include the quotes in the value do not use quotes.  This also applies to character arguments for function calls.

Note that you can also add a format to the %SYSFUNC() call to specify how you want SAS to convert the answer of the INPUTN() function call, which will be a number, to the string that you are assigning to your macro variable.

Here is an example with a few different output formats.

XDATE1 or XDATE4 could be used in SAS code to reference the date.

XDATE2 or XDATE3 could be used as strings to use in TITLE or other place.

%let date1=8/1/2013;

%LET xDate1 = %sysfunc(inputn(&date1,mmddyy10));

%let xDate2 = %sysfunc(inputn(&date1,mmddyy10),mmddyy10);

%LET xDate3 = %sysfunc(inputn(&date1,mmddyy10),date9);

%LET xDate4 = "%sysfunc(inputn(&date1,mmddyy10),date9)"d;

%put &=date1 &=xDate1 &=xDate2 &=xDate3 ;

DATE1=8/1/2013 XDATE1=19571 XDATE2=08/01/2013 XDATE3=01AUG2013 XDATE3="01AUG2013"d

Ask a Question
Discussion stats
  • 4 replies
  • 1 like
  • 5 in conversation