BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
How to debug the code before send to user
and how to optimize sas code typically

8 REPLIES 8
Kurt_Bremser
Super User

Maxim 2: Read the Log.

Fix all ERRORs, WARNINGs and NOTEs beyond those that inform about CPU usage and results.

 

Google will lead you to lots of resources/documentation/papers dealing with code optimization. Learning to optimize code is an ongoing process that never ends (also called "experience"); one can literally write books about the subject so don't expect an exhaustive answer here.

Start by identifying long-running or resource-consuming steps, and see if you can find better methods.

japelin
Rhodochrosite | Level 12
Your question is vague and I am not sure what kind of answer you are expecting.

You can debug data steps with the /debug option.
For overall debugging, you may need to study the testing methodology.

As already mentioned, if the time consumed per step is too much, consider improving the processing method.
However, over-optimization, such as macros, multiple nesting, complex queries, etc., may reduce readability, so over-optimization should be avoided.
ballardw
Super User

@BrahmanandaRao wrote:
How to debug the code before send to user
and how to optimize sas code typically


Optimize what? Amount of code (shorter program text)? Shorter run time? Less memory usage? Amount of network traffic? Disk input/output operations? Code maintenance/flexibility? Time to write program?

And likely a few other things that might be optimized are possible.

 

Many of these involve tradeoffs. To minimize "in memory use" you may have to use much more disk input/output. Or the reverse. Short code can lead to extremely terse statements that are hard to follow and maintain. Writing very flexible program code may require much more coding time to debug and test.

 

Outside of nearly trivial classroom exercises "optimize" requires a lot of specifications as to what the goal of you optimize and what the measure(s) of success might be.

BrahmanandaRao
Lapis Lazuli | Level 10
How to optimize sas code?
Simple anwser expected interviwer
Kurt_Bremser
Super User

@BrahmanandaRao wrote:
How to optimize sas code?
Simple anwser expected interviwer

Congratulations! You found a total idiot trying to disguise as an interviewer.

There is no simple answer, period. Anybody with an IQ above room temperature (measured in Centigrade) knows this.

 

If I wanted to test someone, I'd hand them an older version of a recently improved code and then looked at the suggestions they come up with.

ballardw
Super User

@BrahmanandaRao wrote:
How to optimize sas code?
Simple anwser expected interviwer

Pretty much my previous comments on Optimize what? would be my response to an interviewer.

 

Do not be afraid to ask an interviewer to expand on their questions. The question may be exactly what they want/expect to see if you are aware that the subject of a question is complex. They may even have a script they are following that would have a follow up sucha: "For example, what steps might you take to minimize program run time?". (Which could go into an extensive back-and-forth about the run time environment, tasks, connections to external data bases and other things that come to mind.)

 

A good interviewer for hiring should expect a knowledgeable candidate to ask for clarification on ambiguous questions.

 

Or when in doubt answer "42".

If you don't recognize the reference look up "Hitchhikers Guide to the Galaxy" and related works. In fact the second response to a web search I just ran for "42" returns: https://www.dictionary.com/e/slang/42/

AllanBowe
Barite | Level 11

If you want robust code, I suggest to switch on STRICT mode - ie, to invoke this macro at the start of all your jobs;  https://core.sasjs.io/mp__init_8sas.html

 

And if you want to catch common programming issues before they make it to your GIT repo, you can also try the SASjs lint:  https://github.com/sasjs/lint

Finally, if you want some structure and consistency in the development of your SAS Solution, you could consider scaffolding your project with SASjs.  See:  https://communities.sas.com/t5/SAS-Global-Forum-Proceedings/Scaffolding-SAS-Projects-With-NPM-and-SA...

Disclaimer - my team built the SASjs framework.

/Allan
MacroCore library for app developers
Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 8 replies
  • 1683 views
  • 3 likes
  • 5 in conversation