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
The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

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
The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.
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 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 660 views
  • 4 likes
  • 2 in conversation