PROC SQL: An Efficient Tool for Creating Macro Variables

by Irina 30. April 2007 12:15
PROC SQL offers a lot of useful features, which includes, but is not limited to:

 1) Combine the functionality of DATA and PROC steps into one single step.

 2) sort, summarize, join (merge) and concatenate datasets.

 3) Construct in-line views using the FROM and SELECT clauses.

 4) Line up multiple macro variables using the INTO clause.

EXAMPLE 1 .

The SAS code displayed here can create five sets of macro variables, which are used to create  profiles for 16 states.

proc sql;
select compress(put(count(distinct STATE),best12.))
into :counter
from sashelp.Prdsal2 ;
quit;
%put &counter;


proc sql ;
select state,
min_value,
max_value,
min_act,
max_act
into :state1-:state&counter, :min_value1-:min_value&counter,
:max_value1-:max_value&counter, :min_act1-:min_act&counter,
:max_act1-:max_act&counter
from (select STATE,
min(predict) as min_value,
max(predict) as max_value,
min(actual)-3 as min_act,
max(actual)+3 as max_act
from sashelp.Prdsal2
group by STATE);
quit;

EXAMPLE 2.

This is an example on efficiency of PROC SQL in creating macro variables other than the advantage of shortening the code. These two macro variables are used for two different reasons. Macro date_newd is used to specify the tick marks of the horizontal axis by day. However, macro date_newis used to label the tick marks on the horizontal axis.

proc sql ;
select quote(put(date_new,date7.)),
quote(put(date_new,date7.))||'d'
into  :date_new separated by ' ',
       :date_newd separated by ' '
from
(select distinct date as date_new
 from sashelp.buy);
quit;

Tags: sql, macro

SAS | macro

Related posts

Add comment


(will show your Gravatar icon)  





Live preview

9/7/2010 12:40:15 PM

 

About the author

Irina Spivak Irina Spivak
Team Leader at G-Stat. More...


Send mail Email

Authors

Blogroll

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010

    Sign in

    eXTReMe Tracker