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)

794 questions
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,688
  • 1
  • 26
  • 44
4
votes
1 answer

SAS proc sql returning duplicate values of group by/order by variables

I have some fairly simple SQL that should provide 1 row per quarter per asset1. Instead, I get multiple rows per group by. Below is the SQL, a SAS data step, and some of the output data. The number of duplicate rows (in the below data, 227708)…
pgrebus
  • 41
  • 1
  • 1
  • 2
4
votes
2 answers

SAS to Oracle ODBC - passing a SAS table INTO the database

Can anyone please advise the syntax for passing a table FROM a SAS library INTO an oracle database? example code below (although obviously the connection to the WORK library cannot be referenced in this way) PROC SQL noprint; connect to ODBC as X…
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
3
votes
3 answers

Teradata and SAS with BigInt's

We have a teradata database that is filled with BIGINT datatypes. SAS is the primary analytic engine for the organization. The SAS access library chokes on BIGINT and therefore forces all code to cast variables into a integer or decimal before…
AFHood
  • 1,020
  • 4
  • 15
  • 26
3
votes
1 answer

PROC SQL Numeric value 'NULL' is not recognized

I am trying to use case when statement to compare 2 columns with number and 'Null' value, the Proc SQL will return error as Numeric value 'NULL' is not recognized. How to fix my code? Data type for Column A and B is VARCHAR(10). Table alpha has 2…
Yumeng Xu
  • 179
  • 1
  • 2
  • 11
3
votes
5 answers

How does SAS macro quoting interact with format literals?

Executing locally in a clean session: %let x = %str(put(age, best.)); proc sql; select &x from sashelp.class; quit; This generates the following error: 1 put(age, best.) ---- 22 ---- …
jl6
  • 6,110
  • 7
  • 35
  • 65
3
votes
3 answers

Removing rows between two values in SAS

For the following data I am trying to filter rows, of each group ID, based on these conditions: After every row with type='B' and value='Y' do the following Remove the rows until the next row having type='F' and value='Y'. If there is no B='Y…
ckp
  • 579
  • 2
  • 10
  • 27
3
votes
1 answer

SAS proc contents

I am trying to list content of sas library Sasuser with standard sas 9 setup. From explorer, the library contains Table and catalogs. I am wondering what went wrong. Plus I am able to run proc contents on Sashelp.__all__ and individual table under…
user747229
  • 31
  • 1
3
votes
1 answer

Why does erroneous inner query not make outer query erroneous

Help understand why erroneous inner query does not make outer query erroneous The following query returns 19 proc sql; select count(distinct name) from sashelp.class where name in (select name from sashelp.iris …
Rasmus Larsen
  • 5,721
  • 8
  • 47
  • 79
3
votes
2 answers

SAS PROC SQL - calculate a column using a value returned from macro program

I would like to automatize the following date calculation: add (or substract) X months to a given numeric variable that represents a date in the form YYYYMM, i.e. 201901 stands for January 2019. Example: 201901 + 13 months = 202002 The following…
Chuck Ramirez
  • 245
  • 1
  • 12
3
votes
3 answers

'Invalid column name' error when using Proc SQL in SAS (WPS)

I am testing a very small macro which uses a Proc SQL command to extract from a SQL database. I have used this many times and understand how it works but this time it is stumping me! %macro…
al_sweets
  • 136
  • 10
3
votes
1 answer

SAS Proc SQL how to convert from Number to Character

I am very new to SAS. I want to convert Number to Character. basically I want to use to_char function so I try proc sql; select put(A.column,$11.) as new_column from table A quit; This causing error, what is appropriate way to convert Number to…
SASPYTHON
  • 1,571
  • 3
  • 14
  • 30
3
votes
1 answer

Collapsing data in SAS with PROC SQL

I've been trying unsuccesfully for sometime now to collapse a data set using a PROC SQL with GROUPBY and was wondering if I could get some help. Here is an example of what I am trying to do. Suppose we have the following data: id year parent_id …
student_t
  • 243
  • 2
  • 9
3
votes
1 answer

SAS PROC SQL - How to convert string to number

I want to convert a string to number in a SAS SQL PROC. The oracle-sql functioncs as TO_NUMBER() or INT() do not work. I also tried the CAST( AS ) function but it does not recognize the target type INT or INTEGER.
paolof89
  • 1,319
  • 5
  • 17
  • 31
3
votes
3 answers

SAS Array creation

I am trying to create array that hold a value. proc sql noprint; select count(*) into :dscnt from study; select libname into :libname1 - :libname&dscnt from study; quit; I think the syntax is correct but i keep getting this following error message…
tita
  • 107
  • 1
  • 5
1
2
3
52 53