Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

declare variabe in PROC SQL (SAS)

Tags:

sas

proc-sql

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?

like image 910
dimos Avatar asked Dec 04 '15 21:12

dimos


People also ask

Can you create a new variable in 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!

How do you DECLARE a variable in SQL?

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.

How do I create a new variable in SAS?

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.


1 Answers

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.

like image 122
Reeza Avatar answered Sep 28 '22 08:09

Reeza