BookmarkSubscribeRSS Feed
braam
Quartz | Level 8

I'm just wondering how other people debug their SAS code efficiently. I use SAS windows, and heavily rely on macro code. It's pretty cumbersome to debug for me as my macro code becomes long. Can anybody share some tips with me? Just so you know, I know some options like mprint, mlogic, source2, and symbolgen. It's still hard to read SAS log when these options are turned on. Thanks in advance.

4 REPLIES 4
Reeza
Super User

I almost always build my code initially from a data step/procs, ensure it's working and then covert to a macro, step by step. I also avoid macro's like hell since a lot can be done in data steps and use those instead. I also specifically avoid macro loops and use CALL EXECUTE instead because it seems cleaner to me with a set, separate process though that's not quite true. But it's easier to think of it that way than loops.

 

EDIT: you didn't mention %PUT(). 50 years later, the most power debugging tool is still a PRINT statement essentially. 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

that is one of the thing you just have to deal with when using macros.  As @Reeza says keep it simple &&&&x.ed.

macros are very useful but if you are having problems debugging your own macro think about the people coming in behind you.

 

SASKiwi
PROC Star

@braam  - IMHO if you have long complicated logic in macros, then remove it from them. I'm pretty experienced with macros but I'll only use macros for shortish utility-type functionality, that is small repetitive tasks. Classic examples would be reading and writing spreadsheets and reading SAS dataset contents. There is also a good case for specialist-use macros, but again I use them sparingly and the macro logic is kept simple.

hashman
Ammonite | Level 13

@braam:

If your macro code has become too long, your macro has too many parameters, and/or, God forbid, inundated with quoting functions (including those applied to the parameter values to mask what not), you've overstepped the boundaries of the macro language's purpose and utility. Macros are he11 to debug, as one must understand (a) what happens during their compilation, (b) their execution and then (c) what happens during the compilation and (d) execution of the code they have generated.

 

If you see no alternatives to using macros for SAS code generation (which are plentiful), route your macro-generated code to a text file using the MFILE system option in conjunction with MPRINT. At least then you can run this code stand-alone and see what happens when it executes, rather than guess where in the generated code an array index has run out of bounds because in such a case the only place the SAS log points at is the line where the macro was invoked, so you have no clue. 

 

Kind regards

Paul D.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 473 views
  • 6 likes
  • 5 in conversation