Good day,
I want to use a macro developed by someone else to conduct an interrupted time series analysis. It runs fine but there is no output.
Even if I run the first portion using my dataset, it doesn't save the macro data set.
Would anyone please shed light on why its not saving the data?
%macro itsa;
%itsa(model=sitsa, dataset=work.ID4, outcome=burnout, time=Week, interrupt=14);
%if (&model=sitsa) %then %do;
data work.sitsa_vars;
set &dataset;
t=_n_;
if &time< &interrupt then x=0;
else x=1;
if &time<&interrupt then tx=0;
else tx+1;
keep &time &outcome t x tx;
run;
Based on Appendix in Interrupted Time Series Analysis for Single Series and Comparative Designs: A Guide for Beginners wi...
Thank you!
You seem to have converted the first line of the macro definition into two separate statements. The result is something that probably could never work.
This is what that article has as the first line of the macro:
%macro itsa(model=, dataset=, outcome=, outcome2=, time=, interrupt=, lag=);
Once you have the whole macro defined then you can try to call it:
So the structure of your code should be something more like:
%macro itsa(model=, dataset=, outcome=, outcome2=, time=, interrupt=, lag=);
.... rest of the body of the macro ...
%mend itsa;
... Code that set up the datasets link ID4 that you want to use ...
* Call to the macro ;
%itsa(model=sitsa, dataset=work.ID4, outcome=burnout, time=Week, interrupt=14);
The macro code you've posted appears to be incomplete. For example, it contains no %MEND statement to close off the macro. You also appear to be calling the macro from inside the macro itelf which is never a good idea. This should "work" but still appears to be incomplete:
%macro itsa (model=, dataset=, outcome=, time=, interrupt=);
%if (&model=sitsa) %then %do;
data work.sitsa_vars;
set &dataset;
t=_n_;
if &time< &interrupt then x=0;
else x=1;
if &time<&interrupt then tx=0;
else tx+1;
keep &time &outcome t x tx;
%end;
run;
%mend itsa;
%itsa(model=sitsa, dataset=work.ID4, outcome=burnout, time=Week, interrupt=14);
Thank you!
Just tried the code, it runs but no new data set is saved nor output produced.
the actual macro is longer, as provided in the Appendix linked above. I was just trying to figure out the first part.
The entire macro doesn't work either.
Doesn't work is awful vague.
Are there errors in the log?: Post the code and log in a code box opened with the "</>" to maintain formatting of error messages.
No output? Post any log in a code box.
Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "</>" icon or attached as text to show exactly what you have and that we can test code against.
And when MACRO coding is involved then turn on OPTIONS MPRINT; before running the code so the log will show the generated code (and warning or error messages in closer proximity to the code causing them).
There are no errors, no notes, nothing in the log. Just the code lines in black.
You seem to have converted the first line of the macro definition into two separate statements. The result is something that probably could never work.
This is what that article has as the first line of the macro:
%macro itsa(model=, dataset=, outcome=, outcome2=, time=, interrupt=, lag=);
Once you have the whole macro defined then you can try to call it:
So the structure of your code should be something more like:
%macro itsa(model=, dataset=, outcome=, outcome2=, time=, interrupt=, lag=);
.... rest of the body of the macro ...
%mend itsa;
... Code that set up the datasets link ID4 that you want to use ...
* Call to the macro ;
%itsa(model=sitsa, dataset=work.ID4, outcome=burnout, time=Week, interrupt=14);
Thank you! This may indeed be the issue.
It worked! After restarting SAS session and running it as suggested.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.