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
1
vote
2 answers

explain what is happening in Proc Sql

select Name into :Dataset1-:Dataset%trim(%left(&DatasetNum)) from MEM; I am not able to interpret what is happening here in this statement can anyone give me an explanation. I understand this stament select count(Name) into :DatasetNum from…
user3658367
  • 641
  • 1
  • 14
  • 30
1
vote
2 answers

Extract 6- and 8-digit numbers from text string in SAS

long time reader, first time poster I’ve looked for the answer but nothing that is within my skill to convert to a solution. I'd appreciate any help! I'm trying to extract numbers out of a text data set in SAS, so in ProcSQL or DATAstep. I want to…
1
vote
1 answer

Add minimums to PROC SQL

Somewhat basic question, how can I attach the minimum of another variable in the PROC SQL step? Is there a better way than PROC SQL? Name Payment Tom 30 Tom 45 Tom 15 Bill 20 Bill 100 How could I write a PROC SQL statement that…
Stu
  • 1,543
  • 3
  • 17
  • 31
1
vote
4 answers

creating a new column based on observations in other columns

I am having trouble creating a new variable using conditions, I've tried data steps but to no avail. My data set looks like this right now: A B C D E 1 . 1 1 . . 1 . . . 1 . 1 . 1 I need to look like this A B C D E R . . . . 1 . 1 . . . . . .…
1
vote
1 answer

SAS Proc SQL Not Exist Query vs Data Step a=1 b=0

Trying to measure performance on two small sets of data in order to determine an efficient execution method for a much larger pair of data sets. *This test is being done on a dataset with 32 observations and a dataset with 37 observations. Both…
SMW
  • 470
  • 1
  • 4
  • 19
1
vote
1 answer

SAS EG 5.1 - PROC SQL

How can I use autocomplete in proc SQL queries? For example, when I use proc print I can use autocomplete for libnames, tables and fields. How can I do the same in proc SQL? Thanks
1
vote
1 answer

Creating tables from a master table based on a condition in SAS

The data looks like follow: ID Var1 Var2 A 1 2 A 3 4 B 5 6 B 7 8 C 9 10 D 11 12 I am trying to create subset tables from the above master table in SAS such that each subset table has all the records from the master table…
1
vote
1 answer

How can I populate one dataset from other two datasets? SAS

I have a dataset final with variable A B C D E of which A,B,C are numeric and D,E are character.I want to delete the data from dataset final and populate it with new data from dataset One and dataset Two. Dataset One has variables A B C and dataset…
prathyu
  • 47
  • 4
1
vote
1 answer

Proc SQL in SAS and lag and lead

I'm struggling a bit with a problem I can't quite get my head around. Let's say we have a few columns; IP-address, time stamp, SSN. How would I go finding occurrences where the same IP appears in several records where the time is within the same one…
Joakim123
  • 19
  • 3
1
vote
1 answer

Updating an Oracle table with data from a SAS data set using SAS code

I am rather new to SAS and I have run into a problem that I think probably has a better solution than what I've found so far. I need to update a Oracle db table that has around 1 million rows with data from a SAS data set that has about 10,000…
ChamaraG
  • 95
  • 1
  • 7
1
vote
4 answers

SAS SQL - Two tables (A and B) where the only shared field is the key - want everything in A that is NOT in B

I have two tables where the fields are different except for a shared key. I need to only keep the records with keys that are in A and NOT in B. I don't want records that are only in B or records that are in both A and B (so to exclude anything in…
user3791254
  • 45
  • 1
  • 1
  • 5
1
vote
1 answer

Add timestamp to MMDDYY10. column in PROC SQL (SAS E Guide)

I'm having an issue adding time to a date with PROC SQL. Using PROC SQL, the column I am pulling is formatted as a MMDDYY10.. I need to add x days, y hours, and z minutes to this date. My biggest issue now is just getting a zeroed out time stamp…
Joshua Schlichting
  • 3,110
  • 6
  • 28
  • 54
1
vote
1 answer

Trying Select Distinct in Proc Sql statement for a specific column

I want to use select distinct in a proc sql statement for a specific column. I have around 10 columns, and I don't want to check the duplication for the whole 10 columns, I just want to check the duplication for one column. So when I write the proc…
user3714330
  • 679
  • 12
  • 32
1
vote
2 answers

SAS data update / manipulation

I am relatively new to SAS programming but I have been picking up the basics over the past few months, and its served my needs. However I am currently having trouble and would like some help. I am trying to update a data base and create two new…
Zheren
  • 11
  • 5
1
vote
1 answer

Update database from dataset select in SAS

I am trying to update DB records from SAS dataset. This is what I have tried: proc sql noprint; UPDATE A SET A.IP = U.IP, A.COUNTRY = U.COUNTRY, A.CREATION_DATE = U.CREATION_DATE, A.STATUS = U.STATUS FROM db_table.COUNTRY A INNER JOIN…
Andrew
  • 7,619
  • 13
  • 63
  • 117