I am trying to use a variable on PROC SQL but i cannot find a proper way through the internet. I just want to apply the following code of T-SQL on PROC SQL:
declare @example as int;
set @example=2;
select * from {table} where {column}=@example;
go
How can i apply this code on PROC SQL?
PROC SQL can sort, summarize, subset, join (merge), and concatenate datasets, create new variables, and print the results or create a new table or view all in one step!
Variables in SQL procedures are defined by using the DECLARE statement. Values can be assigned to variables using the SET statement or the SELECT INTO statement or as a default value when the variable is declared. Literals, expressions, the result of a query, and special register values can be assigned to variables.
You can use the FORMAT or INFORMAT statement to create a new variable and simultaneously associate a format or informat with the new variable. To create a new variable using either the FORMAT or INFORMAT statement, make sure that you place the FORMAT or INFORMAT statement first in the DATA step.
The translation to SAS SQL is to use a macro variable, the code looks pretty similar, need to wrap it in a PROC SQL block though.
%let example=2;
proc sql;
select *
from table
where variable=&example;
quit;
EDIT: my original reference to the macro variable was incorrect, use an ampersand in SAS not @ symbol.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With