Hi all,
I'm not sure if there is any solution that i might have missed out, but just looking for some help.
I am trying to make my column variables dynamic. The code is as follows:
%Let len = 7;
%Let col = TEST;
%Let colano = %col%str(_ANONMY);
Data help;
Set Work.dataset;
&colano = cats(of new1 - new&len)
Run;
This line:
&colano = cats(of new1 - new&len)
returns me an error message of ERROR 180-322: Statement is not valid or it is used out of proper order.
Is there anyway i can work around it? There are other parts of the code that i would require to use &col elsewhere, which explains why i need 2 lines of macro to separately define them. (I opened OPTIONS SYMBOLGEN and the macro &len seems to be working fine.)
Thanks for your time to those who are reading this!
This line raises a couple of red flags:
%Let colano = %col%str(_ANONMY);
Try it this way:
%Let colano = &col._ANONMY;
Maxim 2: Read The Log.
37 %Let len = 7; 38 %Let col = TEST; 39 %Let colano = %col%str(_ANONMY); WARNING: Apparent invocation of macro COL not resolved.
So your syntax ERROR 180 is caused by the earlier problem in the %let. Always do your debugging top-down, eliminating issues in the order they appear in the log. Often fixing the first problem will do away with most or all of the others. Do NOT let WARNINGs persist. They are there for a reason and have to be dealt with (Maxim 25).
The result of your faulty %let is this:
40 %put "&colano."; WARNING: Apparent invocation of macro COL not resolved. "%col_ANONMY"
Since the (unresolvable) percent sign can not be used in a valid SAS name, the data step statement will fail.
To concatenate a macro variable value with a string, use this:
%Let colano = &col._ANONMY;
%put "&colano.";
Log:
38 %put "&colano."; "TEST_ANONMY"
Now the macro variable colano contains a valid SAS name.
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.