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

SAS - summing values down observations

I would like to sum values for a set of observations, for a specific column based on a specific identifier. For example, suppose I have data like the below A 4 5 6 B 3 3 2 A 3 4 2 C 3 2 0 B 3 7 3 B 2 4 1 Suppose I want to sum all of the values by…
Ab Di
  • 11
  • 1
  • 1
-1
votes
1 answer

Renames SAS variables to add an underscore

I have about 600 variables that I want to rename dynamically. I used PROC SQL to create a macro variable containing the variable names. Right now they look like: aayyy, abcjjjjj, bbcjjjjj, etc. I want to add an underscore after the first 2, or 3…
-2
votes
1 answer

How to calculate difference between dates of changes in 2 columns in SAS Enterprise Guide?

I have table in SAS Enterprise Guide like below. Data types and meaning: ID - numeric - ID of client DT - date - date of change OFFER_1 - charcter - current offer OFFER_2 - character - offer after change Values in original dataset are not sorted,…
unbik
  • 178
  • 9
-2
votes
1 answer

Proc SQL not returning any columns. Innerjoin

I am trying to gather the information on which store is receiving which SKU along with some other relevant info. The data is in multiple tables so i am trying innerjoin the info. I am using SAS and it runs in SQL Server via passthrough. Below is the…
-2
votes
4 answers

Proc SQL SAS Basic

I want an answer for this. The input I have is: ABC123 The output I want is: 123ABC How to print the output in this format (i.e. backwards) using Proc SQL?
ouilr_
  • 1
-2
votes
1 answer

Update the column which retain the old values using SAS SQL

Need to update the column in the master file, say Column1 has A & B values. I have a different set of a file (mapping file) which has 2 different columns Column1 has only A values & Column2 has only B values which have unique values. My requirement…
vijet
  • 13
  • 4
-2
votes
2 answers

PROC SQL / SAS - Get every month of an active product?

Hi there internet friends, I need your help. I'm an ultra noob with SQL programming and I need help with something I'm working with. Here's what I ave right now in TABLE1 CustNbr ProductNm ExpirationDt(date value) AAA111 Product1 …
THEPIGE
  • 9
  • 2
-2
votes
1 answer

Proc Sql Do Loop in SAS

For an assignment I am asked to create a do loop in Proc Sql statement. My program is not recognizing the m1sales and m2sales. Here are the data sets and the macros that I had to create. The First macro is to set allow people to set the qtr to a…
Marvin Bahr
  • 135
  • 1
  • 2
  • 11
-2
votes
1 answer

Sorting a SAS data without creating a new data set?

I have a hopefully simple SAS question. I have created a data set DATA1 using PROC SQL; CREATE TABLE, etc. In order to create it I ordered some data set randomly and took the first 100 observations. I now want to reorder the dataset. This seems like…
Lepidopterist
  • 391
  • 1
  • 5
  • 21
-2
votes
1 answer

How to select count of distinct key based on indicator in another column?

I have a table which is like this: Geo_Key Var1 Var2..Var50 123 1 0 .. 1 524 0 1 .. 1 323 1 1 .. 1 Where Var1-Var50 represents 50 columns having value 1/0. I want to select count of distinct Geo_Key for each…
user2542275
  • 137
  • 1
  • 7
-3
votes
1 answer

Use multiple proc sql or just 1 to join 3 tables to 1 table?

I have a large table A, with around 5M observations and want to join it with 3 other tables with around 400k observations each. The tables will be joined using different keys to A. All tables have just 1 occurrence of the joining keys only, so they…
-3
votes
2 answers

SAS SQL - How to get cumulative sum in past X months

I have a table like this one: I would like to calculate cumulative sum for column "total" for each cust_id in last x months, based on date_ini and today, so my output would be : Could you help me doing this in sas / proc sql? Thanks!
-3
votes
1 answer

What is the smallest and largest individual for Charge Hour for Job Class?

I need to answer this tricky question in SQL, I tried many ways and finally got this query which retrieves only MAX SUM or MIN SUM without the respective employee. This code retrieves only the MAX charge SUM values but I need it with MAX SUM value…
-3
votes
2 answers

Sum of data at each row in different column in sql

I need to create a different column of total sales which is the total of the sales units till that row. As our sales unit will increase, the total sales will increase row by row. I have attached the image to get the clear idea. Screenshot
21Rahul
  • 15
  • 5
1 2 3
52
53