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

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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);

View solution in original post

6 REPLIES 6
SASKiwi
PROC Star

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);
Nia2023
Calcite | Level 5

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. 

ballardw
Super User

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).

Nia2023
Calcite | Level 5

There are no errors, no notes, nothing in the log. Just the code lines in black. 

 

 

Tom
Super User Tom
Super User

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);
Nia2023
Calcite | Level 5

Thank you! This may indeed be the issue.

 

It worked! After restarting SAS session and running it as suggested. 

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 6 replies
  • 815 views
  • 0 likes
  • 4 in conversation