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

Hello,

 

I'm working on a project in which I have some quite repetitive steps, so I decided to create a macro that takes as parameter a dataset and a string.

When I call the macro for the first time, everything works fine. It's when I call it again right after with a different dataset and string that it goes wrong: the string changes in the results, but the macro's printed data doesnt change and keeps the results from the previous macro call.

I'm afraid I cant post my macro for confidential issues, but I think my problem is quite explicit. Are there any steps I'm missing when calling/ recalling the macro? I'm quite new to SAS so all my macro consists of is:

% macro data_management(table, string)

#repetitive code pasted here#

%mend

 

I even tried deleting the datasets and the end of the macro once the printing had been done, but it still didnt change anything...

 

Regards

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@polpel wrote:

 

I'm afraid I cant post my macro for confidential issues, but I think my problem is quite explicit. Are there any steps I'm missing when calling/ recalling the macro? I'm quite new to SAS so all my macro consists of is:

Make a small reproducible example that does the same thing. Have it print sashelp.class. Usually doing this helps find the issue anyways. 

 

Can we assume you've already run your code with the macro debugging options and examined the log? If not, run the following options, then run your macro and check the log. 

Most likely you're not replacing something and missing an ampersand somewhere. Ie you hardcoded something that should be a macro variable. 

options mprint symbolgen;
*options mlogic;*if needed - makes log really long;

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

You will need to provide more detail about what the macro is doing.

Is it READING from the dataset NAMED in the call?  Or WRITING to that dataset?

What is the STRING parameter and how is it used?

 

As always the key to getting a macro to work is to start with working code.

Does the code inside the macro work without the macro?

Does it work if you recall it (or copy it) and manually edit in the changes the macro makes to the code and run it?

polpel
Fluorite | Level 6

Hello and thanks for the quick response.

First of all, the code does work when it's outside a macro, but I'm having to repeat it multiple times, hence the macro.

Next, I'm reading the data and creating and PROC PRINTing new tables alongside ODS TEXTs. The string is used for the ODS TEXT like so:

ODS TEXT= "my text and &string. included"

Finally, I'm only reading the first table once twice in the macro.

Regards

Reeza
Super User

@polpel wrote:

 

I'm afraid I cant post my macro for confidential issues, but I think my problem is quite explicit. Are there any steps I'm missing when calling/ recalling the macro? I'm quite new to SAS so all my macro consists of is:

Make a small reproducible example that does the same thing. Have it print sashelp.class. Usually doing this helps find the issue anyways. 

 

Can we assume you've already run your code with the macro debugging options and examined the log? If not, run the following options, then run your macro and check the log. 

Most likely you're not replacing something and missing an ampersand somewhere. Ie you hardcoded something that should be a macro variable. 

options mprint symbolgen;
*options mlogic;*if needed - makes log really long;
Kurt_Bremser
Super User

Make up some fake data, post that here (data steps with datalines), and apply your macro logic to it, and post the resulting code also. Then we can try to diagnose your problem. Without code and data it's just guesswork.

ballardw
Super User

Have you run the code with the Options MPRINT and possibly MLOGIC on?

Do you have any notes in the log about "data set x was not replaced" ? That would be an indication that something failed and a previously existing data set from a previous run is used instead of your intent.

 

You may want to delete any temporary data sets BEFORE the macro runs. Often this is done as part of the macro.

And make sure you get all the temporary sets.

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 638 views
  • 0 likes
  • 5 in conversation