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 is hosting free webinars!
Next up: Troy Martin Hughes presents Calling Open-Source Python Functions within SAS PROC FCMP: A Google Maps API Geocoding Adventure on Wednesday April 23.
Register now 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 is hosting free webinars!
Next up: Troy Martin Hughes presents Calling Open-Source Python Functions within SAS PROC FCMP: A Google Maps API Geocoding Adventure on Wednesday April 23.
Register now 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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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