Hello everyone:
I'm writing a task and one of the objects (daterange) returns a couple of dates to two macro variables. I can read these two variables properly to a table with the following code:
options locale=English_UnitedStates; %let d1 = February 24, 2003; data test; dd = input("&d1", nldate200.); run;
But I can't read read the date in the macro variable and save it in another one with the format I need (date9. would ideal). I have tried the following, but it doesn't work.
options locale=English_UnitedStates; %let d1 = February 24, 2003; %let d2 = %sysfunc(inputn("&d1", nldate200.), date9.); %put &d2;
Any help is appreciated.
It's easier to store dates a SAS date values. But with your date as is, you need to make a few changes:
1. Use INPUTN not INPUTC
2. No quotations marks
3. Use %bquote to mask the comma in your value
Try something like:
1 %let d1 = February 24, 2003; 2 %let d2 = %sysfunc(inputn(%bquote(&d1), nldate200.), date9.); 3 %put &d2; 24FEB2003
It's easier to store dates a SAS date values. But with your date as is, you need to make a few changes:
1. Use INPUTN not INPUTC
2. No quotations marks
3. Use %bquote to mask the comma in your value
Try something like:
1 %let d1 = February 24, 2003; 2 %let d2 = %sysfunc(inputn(%bquote(&d1), nldate200.), date9.); 3 %put &d2; 24FEB2003
Thank you Quentin. I just had to add the following line before the line you sent to me because I'm execting this script in Spain and the long format is different here:
options locale=English_UnitedStates;
I tried the same code but with %nrstr, but it didn't work. Yours works perfectly fine.
Thanh you.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.