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

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.

  • NOTE: The quoted string currently being processed has become more than 262 characters long. You might have unbalanced quotation
  • NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
    between a quoted string and the succeeding identifier is recommended.

     
marks.

 

 

Any ideas would be appreciated.

 

Code is attached for your review!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

View solution in original post

7 REPLIES 7
Tom
Super User Tom
Super User

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.

anweinbe
Quartz | Level 8

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"?

Tom
Super User Tom
Super User

@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));
anweinbe
Quartz | Level 8

Tom

 

I apologize for not understanding. Perhaps a few answers to these questions might help...

  • If I take the macro code from the internet, I see it starts with: %MACRO 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); and then ends with this: %MEND EVTSTUDY;
  • If I am using SAS studio, can I take the entire macro code and put it into SAS Program and then call it like you noted below? or does it have to be entered as a task / utility? and then create a SAS program that utilizes the code you provided?

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:

  • Error: Error parsing text XML Parsing Error: not well-formed Location: https:/‌/‌wrds-cloud.wharton.upenn.edu/‌SASStudio/‌main?locale=en_US&zone=GMT-05%3A00&https%3A%2F%2Fwrds-cloud.wharton.upenn.edu%2FSASStudio%2Findex= Line Number 1, Column 1: /‌* WRDS Macro: EVTSTUDY */‌ ^

 

This is my first time trying to utilize and creating a macro. I appreciate your patience with me.

Tom
Super User Tom
Super User

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
);
anweinbe
Quartz | Level 8

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!

 

Tom
Super User Tom
Super User

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: 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 16. 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
  • 7 replies
  • 935 views
  • 0 likes
  • 2 in conversation