BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
acordes
Rhodochrosite | Level 12

Knowing this will be helpful in other ocasion. 

I could refine my question in the following way:

If I have a string like "max(temp(1), temp(2));" stored in a variable cat_str, is it possible to use this in a function.

instead of writing explicitely max_value=max(temp(1), temp(2)); I am looking for using cat_str within the line like max_value=resolve or whatever (cat_str)

Tom
Super User Tom
Super User

@acordes wrote:

Knowing this will be helpful in other ocasion. 

I could refine my question in the following way:

If I have a string like "max(temp(1), temp(2));" stored in a variable cat_str, is it possible to use this in a function.

instead of writing explicitely max_value=max(temp(1), temp(2)); I am looking for using cat_str within the line like max_value=resolve or whatever (cat_str)


No.  You can use the content of a variable to generate SAS code.  You can do it with CALL EXECUTE() or just using PUT statement to write to a file.  But that code will run AFTER the current data step finishes.

 

You can use RESOLVE() to retrieve the results of macro code execution.  But the macro code will not have access to the data that the data step is using.

acordes
Rhodochrosite | Level 12
Tom, that's clear now.
But have a look at @Ksharp 's post.
https://communities.sas.com/t5/SAS-Programming/resolving-a-formula-in-a-dataset/m-p/68123
Isn't this what I'm looking for?
Tom
Super User Tom
Super User

@acordes wrote:
Tom, that's clear now.
But have a look at @Ksharp 's post.
https://communities.sas.com/t5/SAS-Programming/resolving-a-formula-in-a-dataset/m-p/68123
Isn't this what I'm looking for?

If you read that thread it is saying the same thing as I am saying.  Either use the string data to generate code to run later.  Or jump through hoops to push that data into text that can be passed to the %sysevalf() macro function via the resolve() function.  In the marked answer the convert the string var into the character string that represents the value of var before pushing it to the macro processor to be evaluated.

acordes
Rhodochrosite | Level 12
Have a nice weekend
Ksharp
Super User
Tom absolutely deserve this .
hhchenfx
Rhodochrosite | Level 12

Congratulation! Tom.

Thank you for your help with SAS code.

I learn a lot from your post.

HHC

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 21 replies
  • 3117 views
  • 15 likes
  • 5 in conversation