Questions tagged [proc-sql]

proc sql is a SAS procedure used to submit SQL statements to the SAS compiler. For Oracle Pro*C, please use [oracle-pro-c].

proc sql; is a SAS procedure used to submit SQL statements to the SAS compiler. It is optionally terminated by a quit; statement. An example of typical syntax would be:

proc sql;
create table z as
  select * 
  from x
  left join y
  on x.id=y.id
  order by 1,2,3;
quit;

A more 'SAS specific' example would be the direct creation of macro variables, such as:

proc sql noprint; 
select someVariable into: MyMacroArray separated by ' ' 
  from work.Input where varCondition='True';

For further details on syntax, click here (v9.4) or here (v9.3)

610 questions
17
votes
2 answers

Limiting results in PROC SQL

I am trying to use PROC SQL to query a DB2 table with hundreds of millions of records. During the development stage, I want to run my query on an arbitrarily small subset of those records (say, 1000). I've tried using INOBS to limit the…
JDB still remembers Monica
  • 21,669
  • 4
  • 66
  • 107
15
votes
6 answers

Dropping a table in SAS

What is the most efficient way to drop a table in SAS? I have a program that loops and drops a large number of tables, and would like to know if there is a performance difference between PROC SQL; and PROC DATASETS; for dropping a single table at a…
Allan Bowe
  • 11,461
  • 18
  • 65
  • 114
8
votes
7 answers

Is it possible to do a case-insensitive DISTINCT with SAS (PROC SQL)?

Is there a way to get the case-insensitive distinct rows from this SAS SQL query? ... SELECT DISTINCT country FROM companies; The ideal solution would consist of a single query. Results now look like: Australia australia AUSTRALIA Hong Kong HONG…
Rog
  • 3,885
  • 2
  • 22
  • 33
5
votes
5 answers

SQL Passthrough in SAS

Are there any advantages of using SQL Passthrough facility along with SAS?
Tommy
  • 805
  • 3
  • 11
  • 17
5
votes
1 answer

How to develop a third-party SAS PROC?

Is it possible, as a third party, to develop a SAS PROC? I'm thinking of something like a matlab toolbox or an R package. I've looked everywhere for info on how to do this, and the lack of discussion leads me to believe this is Not Done. Can…
5
votes
2 answers

Which statistics is calculated faster in SAS, proc summary?

I need a theoretical answer. Imagine that you have a table with 1.5 billion rows (the table is created as column-based with DB2-Blu). You are using SAS and you will do some statistics by using Proc Summary like min/max/mean values, standard…
user3714330
  • 669
  • 11
  • 28
5
votes
2 answers

SAS Proc sql row number

How do I get the row number of an observation in proc sql, similar to _N_ for a datastep in proc sql? For example proc sql outobs=5; select case mod(, 2) when 0 then "EVEN" else "ODD" end from…
undershock
  • 535
  • 1
  • 4
  • 23
4
votes
2 answers

How to create a table using `Proc SQL` without selecting from existing tables

What is the SAS version of "select from dual"? I want to create a table using Proc SQL without selecting from excisting tables. for instance. Basically I want something like: PROC SQL; CREATE TABLE tmptable AS SELECT 1 AS myvar FROM…
k.dkhk
  • 396
  • 1
  • 5
  • 18
4
votes
3 answers

SAS PROC SQL: How to quickly search if a variable contain a full substring?

I have a problem like this at work: Column Code has the value like, 1000, 1200, A1000, B1200, AAA, BBB, etc. Currently it is separated by spaces, sometimes more than one due to poor data input. And I am trying to check if a record contain a code…
George
  • 4,094
  • 16
  • 46
  • 77
4
votes
2 answers

SAS Warning: CREATE TABLE statement recursively references the target table

SAS allows creation of proc sql create table statement where the table to be created recursively references itself in the select statement e.g.: proc sql; create table t1 as select t1.id ,t2.val1 from …
kristof
  • 49,335
  • 23
  • 82
  • 107
4
votes
1 answer

declare variabe in PROC SQL (SAS)

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…
dimos
  • 127
  • 2
  • 9
4
votes
2 answers

How to count distinct of the concatenation/cross of two variables in SAS Proc Sql?

I know in teradata or other sql platforms you can find the count distinct of a combination of variables by doing: select count(distinct x1||x2) from db.table And this will give all the unique combinations of x1,x2 pairs. This syntax, however, does…
Joe Laert
  • 136
  • 1
  • 1
  • 7
4
votes
3 answers

How to find the length of a numerical variable using PROC SQL

I have a dataset with a column of phone numbers. I want to filter this dataset using PROC SQL WHERE the length of the numbers is at least 7 digits. In normal SQL I can just apply a length function around a number and it works, however in SAS it…
shecode
  • 1,530
  • 4
  • 28
  • 41
4
votes
2 answers

SAS Proc SQL Trim not working?

I have a problem that seems pretty simple (probably is...) but I can't get it to work. The variable 'name' in the dataset 'list' has a length of 20. I wish to conditionally select values into a macro variable, but often the desired value is less…
pyll
  • 1,532
  • 18
  • 39
4
votes
1 answer

convert datetime to date in proc-sql sas

I'm trying to convert datetime22.3 variable to ddmmmyy10. in proc sql, this is giving me ****** in the output column. How can I get the correct values in the output column?
staq
  • 133
  • 3
  • 3
  • 8
1
2 3
40 41