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
0
votes
3 answers

SAS PROC SQL String Manipulation

Can I convert a string column formatted as "YYYY-MM" from SQL back into a Date that uses text. (ie. January, 2014) as a new column using proc SQL? Initially my source is 2014-01 and I would like every row to be converted to the respective month and…
Tinkinc
  • 449
  • 2
  • 8
  • 21
0
votes
2 answers

Number of specific transactions in the last 5 trns

I would like to write sas code (proc-sql). The question is how to create variable VP_Trans (in the table below). The table below is referring to the customers transactions within some period. I would like to calculate how many VP transactions the…
Vendula
  • 29
  • 3
0
votes
2 answers

SAS Counting Occurrences based on multiple layers within set time period

I am trying to count occurrences where the same person was billed for an item, four or more times, by the same place within 30 days of each instance. For example, input would look something like: person service place date A x …
Brad
  • 85
  • 12
0
votes
1 answer

PROC SQL Concat numbers in SAS and format as date - SAS E Guide 5.1

Good morning all, I've got 3 different columns in a data set that represent a month, a date, and a year as numbers. My issue right now is concatenating these together in PROC SQL while keeping them formatted as a date. So far, I've tried the…
Joshua Schlichting
  • 3,110
  • 6
  • 28
  • 54
0
votes
2 answers

How to calculate 'age last birthday' on a given date for a given birthday in SAS PROC SQL step

I want to calculate 'age last birthday' on a specific evaluation date, given a specific date of birth, using a SAS PROC SQL command. How can I do this and are there any limitations? Sample Input DATA INPUTS; infile cards dlm=',' dsd; INPUT DOBDt…
JustinJDavies
  • 2,663
  • 4
  • 30
  • 52
0
votes
1 answer

Proc Means vs Simple Count in Proc SQL for non numeric values

I have many scenarios in which the following query will give me what I need - proc sql; create table test as select ID,count(task) as count from table group by ID; quit; The "tasks" that are being counted are SSN's which are character…
SMW
  • 470
  • 1
  • 4
  • 19
0
votes
4 answers

Join / Merge two tables removing new duplicates [PROC SQL in SAS]

similar questions have been asked on the forums but I seem to have a unique issue with mine. I'm not sure if this is because I don't have a unique ID or because my KEY is my actual data. I hope you guys can help. I am trying to merge two tables (Old…
Wolfspirit
  • 155
  • 3
  • 14
0
votes
1 answer

Using group by in Proc SQL for SAS

I am trying to summarize my data set using the proc sql, but I have repeated values in the output, a simple version of my code is: PROC SQL; CREATE TABLE perm.rx_4 AS SELECT patid,ndc,fill_mon, COUNT(dea) AS n_dea, sum(DEDUCT) AS tot_DEDUCT FROM…
maryam
  • 35
  • 1
  • 6
0
votes
2 answers

SAS dataset size on LINUX is not changing after deleting rows

I have 100GB SAS dataset on LINUX. Space allocated for the dataset after deleting 50 GB data from the dataset is still 100 GB. I'm not sure if this is related to SAS or LINUX. The below code is performing the delete: Proc SQL; Delete * from dataset…
SAS_learner
  • 521
  • 1
  • 13
  • 30
0
votes
1 answer

Using the same condition for multiple variables in PROC SQL statement on SAS

I work with big tables with hundreds of columns. And I keep on running into a problem where multiple columns used as flags (having either a value of 1 or missing) need to be checked for the same condition. For a simplified example, proc sql; …
Krans
  • 3
  • 4
0
votes
1 answer

Get data set with maximum date in name by proc SQL

Suppose I have some data sets in library lib, their names look like Table_YYYYMMDD (e.g. Table_20150101). I want to get a name of a data set with maximum date (YYYYMMDD) and store it in a macro variable. I'm using proc sql and from…
Vikora
  • 174
  • 1
  • 6
  • 19
0
votes
2 answers

select only a few columns from a large table in SAS

I have to join 2 tables on a key (say XYZ). I have to update one single column in table A using a coalesce function. Coalesce(a.status_cd, b.status_cd). TABLE A: contains some 100 columns. KEY Columns ABC. TABLE B: Contains just 2 columns. KEY…
Naga Vemprala
  • 718
  • 3
  • 16
  • 38
0
votes
1 answer

How to convert SAS EG Query with Prompt Values into a proc SQL Code

I have a very basic question I build a query in SAS-EG so that it outputs var1, YEAR and MONTH values but YEAR and MONTH values are prompt values(A and B respectively) It works fine when I use SAS-EG GUI but the code below does not work when I…
Jonsi Billups
  • 133
  • 1
  • 3
  • 15
0
votes
1 answer

SQL Join Update table

I have two tables, Table A has user Id and 5 different product columns(empty, to be filled by count ). Table B has timestamp user id and product id ( purchased at time t). This code id giving error update table_A as table_A set Count_Product_1 =…
Zyerr Dwij
  • 13
  • 1
0
votes
2 answers

Importing table with unknown length from Excel .xlsm

I want to transfer a table from Excel to SAS (version is 9.2 and Excel file format is .XLSM, macro). The column names will be read from the cell B3 and the data will start from the cell B4, like below: A B C D E F G ... 1 2 3 Col1…
user3714330
  • 679
  • 12
  • 32