Hi all,
I am trying to run the attached code, however it doesn't actually do anything. It runs but everything is basically greyed out, like its reading only comments and not actual steps.
I get two errors but I'm not exactly sure how to fix them since I don't see quotes anywhere in the code to even begin fixing it.
Any ideas would be appreciated.
Code is attached for your review!
If you are using SAS/Studio then you should be able to create a program and run it Forget about how to incorporate it into any process flows or task until you get it to run as a normal SAS program first.
Start by making a program with just my little example above that defines a trivial macro and calls it twice. Get that to run.
Then make a new program and paste in the macro definition (as copied from the source without any changes) and run it. It should run without errors but produce no output. If you get errors there then there is some issue with the macro definition you received (or perhaps how you copied it into the program editor).
Then make another new program and write code to call the macro. Run that and test it. Make sure to turn on the MPRINT option so you can see what SAs code the macro generated in the log. You program should look something like this. Replace the parameter values with values that make sense for the data you have. Remember that for the macro call to work the macro has to have been compiled already. So if you restart your SAS session you will need to resubmit the program that defines the macro first before you can run the program that calls it. But once it is defined in your session you shouldn't have to keep copying it.
options mprint;
%EVTSTUDY
(INSET=temp.events
,OUTSET=temp.eventsOut
,OUTSTATS=temp.eventstats
,ID=permno
,EVTDATE=start
,DATA=CRSP
,ESTPER=110
,START=-1
,END=3
,GAP=16
,GROUP=1
,MODEL=ffm
);
All you attached was a macro definition. There was no code to actually run anything.
Are you getting those error when you just submit the macro definition to compile?
Or do you get them when you try to call it. If so then show the code you used to call it.
Maybe that is the issue!
Pardon my ignorance but how exactly do I "call" the macro?
To clarify, you are saying that I provided code that makes up the macro, but I'm never actually submitting code to say "run this macro"?
@anweinbe wrote:
Maybe that is the issue!
Pardon my ignorance but how exactly do I "call" the macro?
To clarify, you are saying that I provided code that makes up the macro, but I'm never actually submitting code to say "run this macro"?
Yes. To define a macro use %MACRO statement and %MEND statement. To call the macro just use % and the name of the macro.
Example:
%macro mymacro(dsn);
proc print data=&dsn.; run;
%mend mymacro;
%mymacro(dsn=sashelp.class(obs=3));
%mymacro(dsn=sashelp.cars(obs=3));
Tom
I apologize for not understanding. Perhaps a few answers to these questions might help...
If I go under "tasks / utilities", would I just create an "advanced task" and past in the entire macro as I found it on the internet"? I tried that and I got this:
This is my first time trying to utilize and creating a macro. I appreciate your patience with me.
If you are using SAS/Studio then you should be able to create a program and run it Forget about how to incorporate it into any process flows or task until you get it to run as a normal SAS program first.
Start by making a program with just my little example above that defines a trivial macro and calls it twice. Get that to run.
Then make a new program and paste in the macro definition (as copied from the source without any changes) and run it. It should run without errors but produce no output. If you get errors there then there is some issue with the macro definition you received (or perhaps how you copied it into the program editor).
Then make another new program and write code to call the macro. Run that and test it. Make sure to turn on the MPRINT option so you can see what SAs code the macro generated in the log. You program should look something like this. Replace the parameter values with values that make sense for the data you have. Remember that for the macro call to work the macro has to have been compiled already. So if you restart your SAS session you will need to resubmit the program that defines the macro first before you can run the program that calls it. But once it is defined in your session you shouldn't have to keep copying it.
options mprint;
%EVTSTUDY
(INSET=temp.events
,OUTSET=temp.eventsOut
,OUTSTATS=temp.eventstats
,ID=permno
,EVTDATE=start
,DATA=CRSP
,ESTPER=110
,START=-1
,END=3
,GAP=16
,GROUP=1
,MODEL=ffm
);
Tom,
I believe that I am close! Just some slight modifications needed, but i'm not 100% sure what they are....
I used the simple code you gave me on the dsn data. That ran over and over without issue! (THANK YOU)
I created a new program, pasted in the code without modification, and then modified the call statement. That is where I must need a small tweak.
currently:
%EVTSTUDY(dsn=sashelp.class(obs=3));
%EVTSTUDY(dsn=sashelp.cars(obs=3));
What do I change the part in parenthesis too? obviously dsn=sashelp.class was the dataset that you used, but what changes do I make? the beginning of my macro looked like this... do I have to put each of these variables in? or do I just do %EVTSTUDY();?
%MACRO EVTSTUDY (INSET=, OUTSET=, OUTSTATS=, ID=permno, EVTDATE=, DATA=CRSP,
ESTPER=, START=,END=,GAP=,GROUP=,MODEL=);
I know I'm close!!! Thank you kindly for working with me!
You cannot call ENVSTUDY with values the parameter DSN that my little example macro used. You need to call it with values for the parameters that it needs. Do not make any changes the source code of the macro (unless you want to change how it works), instead provide your values for the parameters in the macro call.
Re-read my previous post and try using the macro call I suggested. But at this point you need to actually understand what the macro is doing at least enough to know what inputs it wants.
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.