how to create variables in Proc SQL

#1
How do you create variables in proc sql?
For example, in SQL server, I can start my code with:

"
DECLARE @SD AS INT, @ED AS INT, @LD as int
SELECT @SD = 201501, @ED = 201512, @LD = 201603..."

and when I do my code, instead of typing the dates, I can just type in the variables.

I,e

select * from table
where dates between @SD and @ED
 

Stu

New Member
#2
The simplest way would be through macro variables set as SAS date constants.

Code:
%let sd = '01JAN2015'd;
%let ed = '01DEC2015'd;
%let ld = '01MAR2016'd;

proc sql;
   select * from table
   where dates between &sd and &ed;
quit;
To actually create a variable, you would set it as some sort of constant or expression.

Code:
proc sql;
   select 'Constant' as NewVar, *
   from table;
quit;
 
Last edited: