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
BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: 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
BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: 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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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