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
votes
1 answer

SAS code - sum of last N rows for every row

I have a dataset like this for each…
Deniz
  • 53
  • 7
-1
votes
2 answers

Delete rows based on value from first record and value from second record

All, I am currently trying to catch instances where a user made a change, but then the user went back and reverted the change. As you can see in the picture below I need to catch rows where the ID is the same and then the value1 from the first…
user13576801
-1
votes
2 answers

Combination of grouped values in SAS

I am trying to find the various combinations only in the cases where the records in the below dataset only differ by the column type. So for example: the first three rows only differ by the column type Given Dataset ins_id ins_number type 1234 …
Chug
  • 31
  • 6
-1
votes
1 answer

SAS Date conversion from text YYYY/MM to DATETIME20. Format

Hi I have a date format in one table in Text 'YYYY/MM'. example 2018/01, 2020/08 etc. I need to join it with another table where the date is in Number type( and DATETIME20 format attached it it) and convert it to month and compare. Is there any way…
Nika M
  • 1
  • 2
-1
votes
1 answer

Where, Having and OR clauses

I am hoping for your help! I have a set with approved, decline, incomplete, etc transactions. I need to get the latest transaction (due to duplication of transactions; they only differ on the status Approve/decline/etc), but if we need to keep all…
-1
votes
1 answer

Applying Proc format to a date

So I have this code I'm working on to validate dates proc format fmtlib; value drange '01JAN1900'd - '31DEC1909'd = '1900s' '01JAN1910'd - '31DEC1919'd = '1910s' '01JAN1920'd - '31DEC1929'd = '1920s' '01JAN1930'd -…
-1
votes
4 answers

SAS - PROC SQL- Assign a value to a column based on condition based on another columns

I want to assign a value in new_col based on value in column 'ind' when months = 1; idnum1 months ind new_col 1 1 X X 1 2 X X 1 3 Y X 1 4 Y X 1 5 X X 2 1 Y Y 2 …
Swapnil
  • 25
  • 1
  • 9
-1
votes
2 answers

SQL Left join on different columns considering specific conditions

I believe this is an easy one. Just getting started on SQL, so I am finding it a bit tricky. So I am using SQL on SAS, and I want to join two tables but on different columns based on a value of a column. Practical example: Proc sql; create table…
techguy
  • 13
  • 1
  • 3
-1
votes
1 answer

Create a dynamic dataset name with SAS Macros

I am working facing an issue while creating a dataset name by using macro variable. So basically I wanted to create Region_Jun_14 through macro variable. Jun_14 is current month and date. Any lead would be really appreciated :) CREATE TABLE…
vmaha13
  • 11
  • 1
  • 4
-1
votes
1 answer

How to subtract second row from first, fourth row from third and so forth

I have SAS dataset as in the attached picture.. what I'm trying to accomplish is created new calculated field from Total column where I'm subtracting first row-second row, third row-fourth row and so on.. What i have tried so far is DATA WANT2; SET…
-1
votes
1 answer

If condition and a proc sql inside a macro program

I have a control to verify. I want to write a macro variable who includes an SQL proc in case the condition is verified. Exemple: %Macro Control1(List) / minoperator mindelimiter=' '; %IF &Control1 in &List. %Then %do; proc sql; create table…
Mlk
  • 91
  • 8
-1
votes
1 answer

Compare SAS Data Step and PROC SQL using Concatenate function

Following is the Data Step I am trying to work on. I am a beginner in SAS. I want to compare the performance of SAS DATA Step and PROC SQL using concatenation. I tried to do it but i am not getting the same output for the DATA step and proc SQL.…
-1
votes
1 answer

SAS Enterprise Guide - Error while executing workspace job. Server disconnected

So I am only executing a program using proc sql to create a table with statistics on X. After a while, the task bar says complete, but the table is never created and I have this error poping up. Any idea where it can come from? I can run other…
wimz
  • 1
  • 1
  • 3
-1
votes
1 answer

Using a set statement to select many files with a pattern

I am trying to load in a large number of data sets that have a similar pattern to their naming in a set statement ie data output; set &filenames. ; I have seen in other questions a method of creating a macro with all of the names using a proc…
student_t
  • 243
  • 2
  • 9
-1
votes
2 answers

How can I summarize data by year in SQL?

I'm sure the request is rather straight-forward, but I'm stuck. I'd like to take the first table below and turn it into the second table by summing up Incremental_Inventory by Year.…
tubaguy
  • 149
  • 11