There is certainly no shortage of terrific tips and tricks in various SAS blogs from some of our most distinguished SAS in-house experts. But, there's another group of equally qualified experts who don't often get to share their expertise on this channel: our customers. So, I went on a quest to get the inside scoop from various SAS users, polling Friends of SAS members to get their feedback on their favorite SAS tips.
We asked a few of these Friends of SAS members who are regular SAS users to share with us their top SAS tips and tricks for improving performance or something they wished they had known earlier in their SAS career. Based on that, we got a wide range of tips and tricks from a number of different SAS users – ranging from novice to expert and across various industries and product users. Check out some of them below:
FUNCTIONS
Functions are either built into SAS itself or you can write your own customized code that act in the same manner, all of which help in analyzing and processing data. There are a variety of function categories that include mathematical, date and time, character, truncation, and miscellaneous. Using functions makes us more efficient, and we don’t have to re-invent the wheel every time we want to figure something out. With this being said, some of our regular SAS users have a thing or two to say about dealing with functions that may help you out:
“Before you program any complex code, look for a SAS function that will do the task for you.”
- John Ladds, Past President, OASUS
“Insert a line break in a concatenated string, such as: manylines = catx('0a'x,a,b,c);”
- Aroop Ghosh, Principal Consultant, Webtalk Communications
“Use the lag function to create time related variables, for example, in time punch data”
- Yolanda, Analyst, TD
“A good trick that I have recently learnt [sic]which can make the code less wordier is using the functions IFN and IFC as an alternative to IF THEN ELSE statements in conditional processing.”
- Sunny Giroti, Master of Business Analytics Candidate, Schulich School of Business
“IFN can be used in place of IF THEN ELSE to shorten code”
- Neil Menezes, Senior Business Anlyst, CTFS
“Ron Cody’s link from SAS.COM. It has many SAS function examples.”
- John Lam, CIBC
SYNTAX/SHORTCUTS/EFFICIENCIES
You know what they say: time is money. So for a SAS programmer, finding shortcuts and ways to work more efficiently and faster are important to get a job done quicker. Here are a few ways SAS users think can make your life easy while working with SAS:
“Use missover to ensure no records are skipped when reading in a file”
- Scott Bellefeuille, IT Solutions Developer (Merchant Services), TD Bank
“Pressing keys 'Ctrl'+'/' to comment out a line of code.”
- Bunce Leung, Execution Manager, RBC
“Variable Lists - being able to refer to variables using double dashes to indicate all variables between first and last in a dataset is super useful for many procs. The later versions of being able to use the prefix and colon to indicate all datasets with a prefix is a great shortcut as well.”
- Fareeza Khurshed, Manager (Statistical Services), Alberta Treasury Board and Finance
“I like to use PERL in SAS for finding stuff in character variables.”
- Peter Timusk, Statistics Officer, Statistics Canada
“Title "SAS can give you an Inheritance". Have an ODBC driver on your local PC but not on a remote server? No problem. Use rsubmit with the inheritlib option. Your remote server will now inherit the ODBC driver and be able to access a database you thought you could only reach with your PC.”
- Horst Wolter, Manager, TD Bank
“If you want to speed the processing of your program. Run your join statements on the "work" library. It is must faster.”
- Estela Tavares, Economist, Statistics Canada
“When dealing with probability, can logistic be used in all cases? Trick Q - as A is N0. What about the times, probability is 0 and 1. What if the data is heavily distributed on 1s and 0s.”
- Mukul Pandey, Student Business Analytics, Schulich School of Business
“Proc tabulate can perform descriptive statistics better than proc freq and proc means.”
- Taha Azizi, Senior Business Insight Analyst, TD
Your turn
Were any of these tips and tricks useful? Do you use them already? What are some of your top SAS tips and tricks? Please be sure to share in the comments below!
Looking for more tips and tricks? Check out this video featuring six Canadian SAS programmers, including a few Friends of SAS members, who share some of their favourite SAS programming tips.
About Friends of SAS
If you’re not familiar with Friends of SAS, it is an exclusive online community available only to our Canadian SAS customers and partners to recognize and show our appreciation for their affinity to SAS. Members complete activities called 'challenges' and earn points that can be redeemed for rewards. There are opportunities to build powerful connections, gain privileged access to SAS resources and events, and boost your learning and development of SAS all in a fun environment.
Interested in learning more about Friends of SAS? Feel free to email myself at Natasha.Ulanowski@sas.com or Martha.Casanova@sas.com with any questions or more details.
38 Comments
Create your own keyboard shortcuts for code that you use often (e.g. pathname or common macros)
The use of the semi-colon in an operator like in and = to specify "Start with"
Good tips.
Funny to see me again on this video. It's been a while since I viewed it.
Pressing keys 'Ctrl'+'/' to comment out a line of code is a very useful tip. I use it all the time.
I find very helpful to use macro in SAS when handling very large dataset, especially when the computing power and memory resources of my laptop are not sufficient. My simple way is to segment large dataset by class of one or more variables, it is like to chop the large one into many small pieces, after operation on each small piece is done, I merge all small pieces back to have the optimized/target dataset for other analysis use.
Hi. Even if one thinks that IFN and IFC functions might make SAS code difficult to read, you might want to use one of those functions in a situation with a CONDITIONAL LAG (that works since the LAG function is executed at each pass through a data step when embedded in of of those functions ... http://www.howles.com/saspapers/CC33.pdf).
Great tips, thank you!
These are very useful tips!
awesome
Great tips, there's always something new you can learn with SAS.
I personally don't like the IFC and IFN functions. It saves only a small amount of time and makes the code "unreadable" for users that are just beginners in SAS (which is most of my collegues). For me a good program has to have the right balance between efficency and and readability...
Besides PERL, SQL and R also run well or better inside SAS
Many "I didn't know that". Will keep in mind with coding.
great
Great tips. I will surely to using the new ones.
Nice
I like the IFN tip..thanks!
Thanks. This is a great collection of modern day tips.
I have always been impressed with the SAS ability to process and manipulate dates and times.
This is great. Thanks for sharing.
Awesome
Very interesting tips.
List the contents of all the data sets in a library using the keyword _ALL_
proc contents data=libname._all_;
run;
Thank you I learnt a few new things.. the inheritlib is something that I did not think was possible!! WOW!!!
Thanks for the Tips
Lots of tips! Just need some form of indexing so I can search for them more efficiently.
My tip is to use compress datasets when dealing with very big datasets that are quicker to decompress by the cpu than read on the disk.
I'm always amazed how the little tips like these can turn out to be so impactful.
I still love SAS functions.
Thanks Natasha. Everyone in SAS including yourself have done an excellent job providing various platforms with plenty of helpful resources for SAS user group. The community you guys have built is second to none!.
Thanks Rodger for the kind words!
My tip was awesome!
In a DATA statement you can use
array X[*] _numeric_;
array Y[*] _character_;
and use DO function say to rename missing values or change some numeric values such as 999, 88 etc to missing if that was what it means.
Google is also a handy tool, it has not yet failed me when I'm stuck and need some ideas on SAS stuff.
Great tips. I definitely will use them.
I agree with John Ladds. The ever increasing amount and scope of available functions has always been a main reason why SAS has been my choice for analytical software.
My tip - try out one question a day from https://sasensei.com! It only takes a minute, and you're bound to learn something new..
Thanks for sharing another great resource!