BookmarkSubscribeRSS Feed
sasboy007
Calcite | Level 5

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. 

4 REPLIES 4
Kurt_Bremser
Super User

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";

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

ballardw
Super User

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

Tom
Super User Tom
Super User

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1338 views
  • 1 like
  • 5 in conversation