DATA Step, Macro, Functions and more

Repeated Macro Calls Giving Different Results

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Repeated Macro Calls Giving Different Results

[ Edited ]

I'm a peculiar situation where I appear to get different results from a particular macro if the macro is called first in the code versus if it's called later in the code (presumably after the macro has been called with other parameters). I would generally expect a macro to return the same results if giving identical parameters. 

 

I haven't been able to reproduce this "error" in a more controlled manner (hence the lack of test code), but my macro uses PROC LOGISTIC to create a model from a subset of my data, save the results (list of variables, etc) to a given "total" dataset, The intention is for the macro to be run several times to work on different subsets of the data and append the results to that same "total" dataset for later output. 

 

Any tips on troubleshooting this? 

 

I do sincerely apologize for the unorthodox question without proper test code, but I appreciate any suggestions/tips. 


Accepted Solutions
Solution
‎03-20-2018 09:09 PM
Super User
Posts: 24,010

Re: Repeated Macro Calls Giving Different Results

Posted in reply to ImSpartacus

Things to check - the scope of your macro variables. Are you accidentally setting/resetting something?

Or modifying your data at some point and then running your model? Are you using a model selection method?

View solution in original post


All Replies
Solution
‎03-20-2018 09:09 PM
Super User
Posts: 24,010

Re: Repeated Macro Calls Giving Different Results

Posted in reply to ImSpartacus

Things to check - the scope of your macro variables. Are you accidentally setting/resetting something?

Or modifying your data at some point and then running your model? Are you using a model selection method?

Occasional Contributor
Posts: 9

Re: Repeated Macro Calls Giving Different Results

Thanks for your thoughts.

It turned out that I WASN'T resetting a particular dataset of potential regression variables that was being appended. So everything worked, but the forward selection had "too many" variables to pick from in the macro calls that ran later on in the program.

I appreciate the feedback from everyone and I genuinely wish I could pick you all!
Super User
Posts: 6,934

Re: Repeated Macro Calls Giving Different Results

Posted in reply to ImSpartacus

When you say "several subsets" of the data, I'm picturing randomly selected subsets.  That could automatically make the results slightly different each time.

 

Even if you are controlling the seed for the random selector, the data set may be different.  For example, it may be sorted differently later in the program, causing the random selection to choose a different sample (even when the seed has not changed).

Occasional Contributor
Posts: 9

Re: Repeated Macro Calls Giving Different Results

[ Edited ]
Posted in reply to Astounding

In this particular situation, I'm using a relatively simple "filtering" method, but as a side note, I do use have a similar macro that does randomly subset data, and I didn't know about the effect of sorting on random selection (despite using the same seed). I'll have to remember that!

Thank you very much for your thoughts!

Super User
Posts: 10,574

Re: Repeated Macro Calls Giving Different Results

Posted in reply to ImSpartacus

Hidden side effect. One of your macro variables you assume to be local might be global. Or a dataset that you assume to he static is actually changed.

Without code, and data to test it against, we can only guess.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 136 views
  • 3 likes
  • 4 in conversation