Look what Santa has for lazy programmers

3

On any given day, on an average, good programmers spend maybe about 10-20% of their time writing code. And the remaining 90% thinking, researching, and experimenting to find the best design. With so much thinking time, they need every bit of help to reduce the amount of typing time. Not-so-good programmers spend much of that 90% debugging code by randomly making changes and seeing if that works, but I’m sure you’re not one of them!

So why not let Santa come to the rescue just for the programmers in your holiday list who suffer from “lazy programmer syndrome.”

1.       The why-do-I-have-to-type-a-million-variable-names programmer

Fed up of typing out long winded variable names. Worry no more. Variable shortcuts make mincemeat of all the typing work.

Numbered range list

Try X=Sum(of var1-var4);

Instead of x=sum(var1, var2, var3, var4)

Name range list

2 hyphens in the variable list gets you everything from var1 to qtr, doesn’t matter what’s in between

Try X=Sum(of var1 -- qtr);

Instead of x=sum(var1, second, q3, qtr)

Prefix list

Try X=Sum(of var:);

Instead of  x=sum(var1, varjan, varfeb, vartot);

Special name list

Try X=Sum(of _numeric_);

Instead of x=Sum(var1, qtr, varjan, varfeb);

2.       The I’m-too-cool-to-type-the-full-path programmer

Give them this

Libname santa ‘.’;

Instead of Libname santa ‘s:\workshop’;

Just be sure to tell them that they need to at least make sure that their working folder in their SAS session points to the right data folder (red arrow).

3.       The I-hate-gluing-data programmer

Sick of having to type multiple vertical bars to glue character data together. You’ll feel so much better when you use the slick and feline CATX operator. Not only does it glue together your character values, but it also converts numeric if you happen to have mistakenly forgotten to convert. Now how’s that for a bonus stocking stuffer?

Which one do you like?

Phone = cat(‘(‘, Code,’) ‘,Mobile);

Or

Phone='(' !! put(Code,3.) !! ') ' !! Mobile;

Do you suffer from the lazy programmer syndrome? Looking for more ways to cut down code? Try our SAS Macro Language 1: Essentials class.

"We will encourage you to develop the three great virtues of a programmer: laziness, impatience, and hubris." -LarryWall, ProgrammingPerl (1st edition), OreillyAndAssociates

“A great lathe operator commands several times the wage of an average lathe operator, but a great writer of software code is worth 10,000 times the price of an average software writer.” –Bill Gates

Share

About Author

Charu Shankar

Technical Training Specialist

Charu Shankar has been a Technical Training Specialist with SAS since 2007. She started as a programmer, and has taught computer languages, business and English Language skills. At SAS, Charu teaches the SAS language, SQL, SAS Enterprise guide and Business Intelligence. She interviews clients to recommend the right SAS training to help them meet their needs. She is helping build a center for special needs kids in this project. http://www.handicareintl.org/pankaja/pankaja.swf

Related Posts

3 Comments

  1. Hello Charu, I have a question regarding time series forecasting tool.
    Is it possible to create a macro which will call the time series tool?
    Thank you,
    Have a great day,
    Alex(Sasha)

  2. Anders Sköllermo on

    Hi! Numbered range list, Name range list and Prefix list are very good examples of how you can use them, from SAS point of view.
    But is it good for you as a tired programmer, or your friend who will take over this program to use these very short notations?
    According to good programming standards your should specify clearly somewhere in your program, that You want to add together, the NON-MISSING values of:
    var1, var2, var3, var4
    var1, second, q3, qtr
    var1, varjan, varfeb, vartot
    var1, qtr, varjan, varfeb

    So, then it easy to use cut and paste in the editor, to write clear code.
    A good alternative is perhaps to use one or several MACRO variables, to specify what variables shall be summed. Then put the macro variable value e.g. to the SAS Log.

    A "bad" example - in April and May, etc:
    Data work.sum_so_far;
    set work.sales_data;
    X=Sum(of var:);
    keep var1 varjan varfeb vartot; /* VARMAR should have been included */
    run;

    • I agree Anders.thanks for pointing it out. if a user used these shortcuts without knowing their data. they could end up with an abnormally high number like the variable qtr1sum has.. it sums up every variable with the prefix of qtr. Ultimately a SAS user has to exercise discretion in using these shortcuts & remember my # 1 favourite rule for all data workers: KNOW THY DATA :)
      data tots;
      set orion.employee_donations;
      qtrmin=min(of qtr1- qtr4);
      qtr1min=min(of qtr:);
      qtrsum=sum(of qtr1- qtr4);
      qtr1sum=sum(of qtr:);
      run;

Back to Top