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.
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);
run;
%put "&xdate";
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.
Or use a proper date literal such as '01AUG3013'd
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
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.