BookmarkSubscribeRSS Feed
supp
Pyrite | Level 9

Hello SAS community! Recently I have been posted a few scenarios to get help on real world situations. For every scenario I have posted I have received multiple valid responses. Valid in the sense I get the expected or desired output. While my scenarios have not been advanced in their complexity they have been proxies for real world situations. I have been very impressed with the solutions the community has provided. For every scenario I have posted I have received three or more approaches/solutions to the problem. The hard part is trying to decide on which approach to use!

 

This got me thinking that a fun side project would be to find or develop a protocol for comparing different solutions for the same problem. Then applying  the protocol to attempt to identify which solutions might be better from an efficiency standpoint. I have recently gotten back into SAS programming and consider my SAS programming abilities to be moderate (not advanced but also not beginner). I think this might be a fun project to work on and a great way to develop my SAS knowledge.

 

I found this paper detailing an approach for identifying best practices. It seems pretty good using run time, CPU time, memoy and I/O operations as measures for code efficiency. 

 

https://www.lexjansen.com/nesug/nesug10/ma/ma09.pdf

 

My question to the community is what other considerations should be taken into account when trying to compare code to determine a preferred solution to a problem? Are you aware of any other papers or resources on this topic?  Any general thoughts or feedback on this idea?

 

Thanks

-supp

5 REPLIES 5
Shmuel
Garnet | Level 18

Just few points to consider:

 

Using options compress=yes; will result in - depending on your data - increasing CPU time, saving I/O and 

all in all decrease run time.

 

Thus beyond using KEEP of relevant variables in SET or DATA= satements, and WHERE condition to skip

non relevant observations.

 

Deleting intermediate datasets, not used in farther code, releases space and saves run time (CPU and may be I/O).

 

Finnally, you should compare results of the different methods, to be sure you got same results, otherwise there is probably 

some kind of bug (in code or in design). 

supp
Pyrite | Level 9
Excellent points. Thank you @Shmuel
Kurt_Bremser
Super User

Start with Maxims 4, 30 and 29. A step that does not use excessive resources and finishes in short time should always use the simplest and most easily understood code (the costliest resource in our field of work is programmer's time).

 

Only when you run out of resources (or your code causes problems for other concurrent jobs), or need excessive time ("excessive" in this context is of course highly subjective), test for and then implement the code that is more efficient in these regards. The more "exotic" the final solution is, the more attention needs to be given to proper documentation. See this quote from Maxim 12:

"The next one to maintain that piece of code might be your five-year-older self. Be nice to her."

supp
Pyrite | Level 9
@Kurt_Bremser, thanks for chiming in. That is an impressive lit of Maxisms you have put together!

I wonder if there is a way to score or rank code based on level of complexity? All else being equal the simpler solution is the better solution.
Kurt_Bremser
Super User

@supp wrote:
@Kurt_Bremser, thanks for chiming in. That is an impressive lit of Maxisms you have put together!

I wonder if there is a way to score or rank code based on level of complexity? All else being equal the simpler solution is the better solution.

If computers could already do that, we'd be out of our jobs anyway.

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