January 2012 Quick Tips

Tip #1: Use SYMPUTX to do the work of SYMPUT, TRIM, LEFT, PUT.

Tip #2: Use Enterprise Guide to join up to 32 tables at once with a GUI.

Tip #1

Creating macro variables is often done at data step execution with CALL SYMPUT. 

Because macro variables are always character, when populating with a numeric data step value to avoid conversion messages,

it is necessary to convert the number to character with PUT and then trim off leading and trailing blanks.

As you can see three nested functions are used within the SYMPUT call with a lot of parentheses.

 

data _null_;

call symput('totobs',left(trim(put(nmemb,5.))));

set indata nobs=nmemb;

stop;

run;

title "&TOTOBS Observations in the Dataset";

proc means data=indata;

run;

 

An alternative is to use CALL SYMPUTX which acts exactly as CALL SYMPUT does, except if the input argument is numeric, SYMPUTX automatically converts to numeric using the BEST. format, and trims leading and trailing blanks, and makes for much less coding.

 

data _null_;

call symputx('totobs',nmemb);

set indata nobs=nmemb;

stop;

run;

Tip #2

 

Use Enterprise Guide to join up to 32 tables at once with a GUI

 

•          In EG’s Query Builder, click on Join tables, and the join interface will pop up.

•          You can add tables to a query or join existing tables.

•          EG will find a join key if it finds matching variable names or the user can manually specify a key.

•          User can choose what type of join and other options.

•          The interface will show all of the tables, along with the join attributes, including a Venn diagram.