Monday, January 23, 2017

Hack 4.9 Removing Blanks From Macro Variable Text


SAS Programming Professionals,

Did you know that the CALL SYMPUTX routine can save you keystrokes and lead to leaner, cleaner SAS programs? 

In the past, when we needed to load a SAS macro variable with a character string that might contain blanks, we would do the following:

call symput('MACROVAR',trim(left(charvar)));

This can be reduced by 12 keystrokes by using CALL SYMPUTX in the following manner:

call symputX('MACROVAR',charvar);

Think how happy your tired fingers will feel with a savings like that!

My older programs are littered with "trim(left)" CALL SYMPUT's and I would bet that yours are too.  I plan to replace mine as time and circumstance allows when I open my programs to address other issues.  How about you?

Best of luck in all your SAS endeavors!

---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

The hack above is an excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers

No comments:

Post a Comment