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

R Markdown SAS code chunks with proc sql not performing as expected

I'm using R Markdown to create a SAS proc sql tutorial but I have found several instances where code chunks with proc sql are not working as expected. First, the outobs=N and inobs=N options will not evaluate and result in this error: Error in…
Leah
  • 11
  • 3
1
vote
2 answers

week function in proc sql

does any one know how to get weeknumber within sas proc sql ?
iamjeannie
  • 61
  • 2
  • 5
1
vote
2 answers

extend list to include factor transforms in SAS

I have a dataset like this data have; input ID Label; datalines; Factor_1 Assets Factor_2 Liabilities Factor_3 Bonds ; run; I'm looking to create a new dataset to accomodate a factor transformation and I will need to update my dictionary as…
1
vote
2 answers

Insert into function with SAS/SQL

I want to insert values into a new table, but I keep getting the same error: VALUES clause 1 attempts to insert more columns than specified after the INSERT table name. This is if I don't put apostrophes around my date. If I do put apostrophes then…
resonance1
  • 97
  • 14
1
vote
1 answer

Proc sql calculate previous saturday or end of last week

Is there a better way of doing this? asof = CAST(DATEADD(week, DATEDIFF(week,'19000101',CURRENT_TIMESTAMP), '1899-12-30T19:00:00') AS DATE) Basically, I am trying to use previous week's Saturday as my filter on Proc Sql. No matter what day I…
JCP
  • 19
  • 2
  • 7
1
vote
1 answer

Count unique patients and overall observation using PROC SQL

Working in SAS but using some SQL code to count the number of unique patients but also the total number of observations for a set of indicators. Each record has a patient identifier, the facility where the patient is, and a group of binary…
1
vote
1 answer

How to use MACRO in PROC SQL to create consecutive variables in SAS

I want to simplify the SAS code in PROC SQL by using MACRO. I already success in data step by using MARCO to replace the YYMM. The YYMM is consecutive for many months. The example data and my original code are as following. …
Terence Tien
  • 329
  • 1
  • 3
  • 15
1
vote
1 answer

PROC SQL: collect_set or group_concat equivalent?

Given the following data, data tmp; input class $ age gpa graduated; datalines; A 16 2.47 1 B 13 3.65 1 A 13 2.04 0 B 12 2.3 0 C 15 3.58 1 ; run; I'm seeking this output: class|unique_ages A|13, 16 B|12, 13 C|15 Coming…
blacksite
  • 12,086
  • 10
  • 64
  • 109
1
vote
2 answers

SAS: Hash Table Lookup using indexed column as hint

At work I have a 200M rows (300+ columns, ~200GB) claims table that is indexed by member number (memno) and date of service (dos). Twice a month I have to pull 50,000 member number's claims from a fixed date range (say 1/1/2017 to 5/1/2018), where…
George
  • 4,514
  • 17
  • 54
  • 81
1
vote
1 answer

Duplicate rows based on "from" and "to" dates

I've got a table like (code in SAS SQL but I can convert reply from SQLServer engine as I have a bit of experience in it): proc sql; create table work.temp1 (date_from num informat=date7. format=date7., date_to num informat=date7.…
Mateusz Konopelski
  • 1,000
  • 4
  • 20
  • 37
1
vote
1 answer

SAS PROC SQL - How to add months to a date

How can I add months to a date? I've tried the function ADD_MONTHS(, 6) and DATEADD(Month, 6, ) but both functions are not recognized. What's the correct function to use?
paolof89
  • 1,319
  • 5
  • 17
  • 31
1
vote
1 answer

SAS - What is the SQL language used in a PROC SQL?

I'm new to SAS and I'm using the PROC SQL functionality. I can not understand which is the sql language used in the PROC SQL. It seems similar to Oracle-Sql but some functions are not available. Can anyone clarify this point?
paolof89
  • 1,319
  • 5
  • 17
  • 31
1
vote
2 answers

Proc SQL DATE() in where statement

I'm trying to edit this code to be dynamic as I'm going to schedule it to run. Normally I would input the date in the where statement as 'YYYY-MM-DD' and so to make it dynamic I changed it to DATE(). I'm not erroring out, but I'm also not pulling…
Lauren Neely
  • 31
  • 1
  • 5
1
vote
1 answer

Total process time PROC SQL, understanding the log

I'd like to understand the time log better to improve performance. My real time is typically much bigger than the cpu time. Is it expected ? Is the difference due to disk access ? Are the in memory operations included in CPU time or in real time…
moodymudskipper
  • 46,417
  • 11
  • 121
  • 167
1
vote
2 answers

Make a string in SAS from one column

I have a dataset in SAS and I want to Convert one column into string by the Product. I have attached the image of input and output required. I need the Colomn STRING in the outut. can anyone please help me ?
21Rahul
  • 15
  • 5