BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
JordiGC
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

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

View solution in original post

2 REPLIES 2
Quentin
Super User

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
JordiGC
Obsidian | Level 7

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. 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1402 views
  • 4 likes
  • 2 in conversation