BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sfinch
Calcite | Level 5

In the following code, I pass in a string "1990" and build another string "01jan1990".  I now need to convert this string to a date.  The first two LET statements work fine:


%LET yyyy=&sysparm;
%PUT &yyyy;

%LET lwrs = 01jan&yyyy;
%PUT &lwrs;

%LET lwrd = %INPUT(&lwrs, date9.);
%PUT &lwrd;


but the final LET statement gives rise to "ERROR: Open code statement recursion detected."  How can this conversion be correctly performed?  Thank you!

 

P.S.  I examined

https://communities.sas.com/t5/Base-SAS-Programming/ERROR-Open-code-statement-recursion-detected/td-...

https://communities.sas.com/t5/SAS-Procedures/intnx-macro-variable/td-p/217078

but still cannot find a workaround.  Apologies if this is an FAQ.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The %input is not the same as the datastep input function.

And the macro language doesn't like "input" it wants the specific INPUTN or INPUTC

 

Try:

%LET lwrd = %sysfunc(INPUTn(&lwrs,date9.));

 

You will have the numeric value for the date such as 10958 result for 01Jan1990.

View solution in original post

2 REPLIES 2
ClarkLawson
Obsidian | Level 7

the %INPUT statement is for textual input.

 

To convert characters and numeric within a macro function I always tend to use %sysfunc() around a SAS function. You can either use PUTN or INPUTN like below depending on the outcome you wish.

 

%LET lwrd = %sysfunc(putn("&lwrs."d, date9.));

 

 

ballardw
Super User

The %input is not the same as the datastep input function.

And the macro language doesn't like "input" it wants the specific INPUTN or INPUTC

 

Try:

%LET lwrd = %sysfunc(INPUTn(&lwrs,date9.));

 

You will have the numeric value for the date such as 10958 result for 01Jan1990.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 5768 views
  • 0 likes
  • 3 in conversation