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
2
votes
2 answers

SAS PROC SQL update with inner join

Last time I checked, this is completely legit SQL code that even Access can handle. Not sure why I'm getting the following error from SAS UPDATE fu_coding INNER JOIN old_form16 ON fu_coding.CSPCCID = old_form16.CSPCCID SET fu_coding.CHANGED =…
blacksaibot
  • 265
  • 2
  • 12
2
votes
2 answers

How to pull the last N number of dates in SAS SQL

I am dealing with a large dataset (30 million rows) and I need to pull the most recent three dates (which may have an indeterminate number of rows attached to them) so like 03MAR2016 might have 2 rows 27FEB2016 might have ten and 25FEB2016 might…
Kumachorou
  • 37
  • 3
2
votes
2 answers

Union tables with different columns

I have two large tables (~1GB each) with many different columns on which I want to perform a union all in sas. Currently, I use the following method with proc sql and union all. SELECT A, B, '' as C from Table_1 UNION ALL SELECT '' as A, B, C from…
Brian
  • 26,662
  • 52
  • 135
  • 170
2
votes
1 answer

SAS Macro function return SQL result

I'm newbie in SAS and macro functions. I'd like my code more "DRY", so i'd like to put my useful sql queries into macro functions who return the result. For example, I've tried this : %macro getName; %local nameq; PROC SQL noprint; SELECT…
ren0
  • 23
  • 3
2
votes
3 answers

Using SAS or SQL find the first and last non-empty value within a row?

My data is currently in the form: ID Fill1 Fill2 Fill3 Fill4 Fill5 1 01JAN2014 28JAN2014 26FEB2014 . . 2 . 05FEB2012 03MAR2012 02APR2012 …
Justin
  • 55
  • 2
  • 7
2
votes
3 answers

SAS - need to use .first .last obs but how to specify with multiple key/compound key?

I'm trying to use .first and .last obs to get rid of BOTH duplicates in pairs of duplicates (by writing out dupes and uniques to separate tables). The issue is that my key is made up of several variables - a household id, product name, and date…
user3791254
  • 45
  • 1
  • 1
  • 5
2
votes
2 answers

Locate a sub-string within a string Oracle

I am trying to locate a substring within a string. Everything I find on the net is locating its position. I don't care about the position and given the position on every row floats I cant say regexp_instr(X, 10, 5). I am looking to say if X in…
Tinkinc
  • 449
  • 2
  • 8
  • 21
2
votes
1 answer

SAS Proc SQL how to perform procedure only on N rows of a big table

I need to perform a procedure on a small set (e.g. 100 rows) of a very big table just to test the syntax and output. I have been running the following code for a while and it's still running. I wonder if it is doing something else. Or what is the…
JasonSmith
  • 499
  • 1
  • 6
  • 8
2
votes
3 answers

SAS - sub select with like

hope everyone had a good weekend. I have a table (tableA) with one column that has values such as the below: Column1: xyz-12345678 rdr-32343234 fgm-23423423 Then i have another table (tableB) with one column that has all the values in…
vbala2014
  • 161
  • 2
  • 6
  • 15
2
votes
2 answers

How to write conditional where statement in SAS Proc SQL?

I have a macro that would be used for multiple conditions. %macro Average(data=, tablename=, element=, variablename=, time =); PROC SQL; CREATE TABLE &tablename. AS SELECT ID, AVG(&element.) AS &variablename. FROM &data. …
baikafei
  • 35
  • 1
  • 4
2
votes
1 answer

Getting a WARNING when inserting a row using PROC SQL

data RuntimeStats; length PgmName Status $100 PeopleNotified $ 400 AttachRowCount $4000 ErrorFound $1000 unix_prcs_id $20 program_restart_step 8 Email_Subject $200 dt_prcs_data $10; id=&nextid; userid_exec="&userid"; …
SAS_learner
  • 521
  • 1
  • 13
  • 30
2
votes
2 answers

Sql, Compged, Min and blanks

I'm comparing 4 strings using compged in sql here is an extract: MIN(compged(a.string1,b.string1), compged(a.string1,b.string2), compged(a.string2,b.string1), compged(a.string2,b.string2)) < 200 Unfortunately there are times that a…
matthew
  • 21
  • 2
2
votes
1 answer

Order of rows returned by PROC SQL

I'm wondering about the order in which data is returned by PROC SQL if there is no sort or group by statement. Is it always the same? For example, suppose I do this: proc sql; create table cusips as select a.cusip as c1, b.cusip as c2 …
itzy
  • 11,275
  • 15
  • 63
  • 96
2
votes
3 answers

How to create this macro with conditions?

Sample input data: FirstName LastName Group Age LastVenue Position Jack Smith ULDA 25 TheaterA 1 Jesse James GODL 37 TheaterB 12 Jane Doe ULDA 29 TheaterA 3 Izzy…
Jax
  • 27
  • 6
2
votes
2 answers

PROC SQL error: "ERROR: Expression using equals (=) has components that are of different data types."

I am trying to subset my data with PROC SQL, and it is giving me an error when I use my variable TNM_CLIN_STAGE_GROUP. Example below: PROC SQL; create table subset as select ncdb.* from ncdb where YEAR_OF_DIAGNOSIS>2002 AND SEX = 2 AND…
vokey588
  • 203
  • 1
  • 3
  • 9