Coder Social home page Coder Social logo

sas-letput's Introduction

The %let statement is an effective way to trim leading and trailing spaces from macro variable values. The %put statement is an effective way to display macro variable values to the log. Using %let and %put together looks like this.

%let mymac = &mymac;
%put mymac = [&mymac];

Unfortunately, typing the macro variable name 4 times can become quite tedious. This repository contains a simple macro %letput that can be used to strip a macro variable and displaying its value in your log.

data _null_;
   x = "   my value   ";
   call symput("mymac",x);
run;

%put mymac = [&mymac];

%letput(mymac);

Log excerpt:

letput log excerpt

The benefits of %letput vs. %let + %put are:

  1. You only have to type mymac once.
  2. You don't have to type the [brackets].
  3. The resulting macro variable value has been stripped (spaces removed from beginning and end).
  4. The value displayed in the log is indented and color coded.

You can read more about the macro in the SESUG paper.

GOTCHA

Of course, this being the SAS macro language, nothing is perfect. If your macro variable values have double quotes in them you will get an error with %letput. Many alternative approaches were explored, but each came with its own shortcoming. It was decided that double quotes was the least likely item to show up in a macro variable value and so we live with that possibility. On the plus side, if you do have double quotes in your macro variable values, simply comment out %letput for that macro variable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.