BookmarkSubscribeRSS Feed
thejianguy
Calcite | Level 5

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!

3 REPLIES 3
Astounding
PROC Star

This line raises a couple of red flags:

 

%Let colano = %col%str(_ANONMY);

 

Try it this way:

 

%Let colano = &col._ANONMY;
Reeza
Super User
Have you considered arrays? Is this your actual use case?
Kurt_Bremser
Super User

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.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2948 views
  • 3 likes
  • 4 in conversation