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

Splitting a cell up using delimiters, but the delimiter is before the desired split location

I have some data in the form of a column in a dataset (named Person_details), where each has an unknown number of names, with the name (split up by spaces), followed by an underscore, followed by that persons identifier (7 characters). Is there a…
1
vote
1 answer

Deleting rows based on multiple columns conditions

Given the following table have, I would like to delete the records that satisfy the conditions based on the to_delete table. data have; infile datalines delimiter="|"; input id :8. item :$8. datetime : datetime18.; format datetime…
Kermit
  • 3,112
  • 2
  • 10
  • 34
1
vote
1 answer

SAS : Problem with put function in a proc sql

I'm trying to create a table using a sql procedure with a column in date9 format, however, despite the put function I use with the date9 parameter, my column is created in string format, even though I have no error indicated in the log. Here is what…
Alex Zak
  • 11
  • 2
1
vote
1 answer

PROC SQL -- Attempting to create dummy variable based on value in one column and group in another column

I have three columns indicating the name of a center, the center's state, and whether or not the state associated with the center. I am trying to see if a center is part of a chain that operates only in intervention states, never in intervention…
1
vote
1 answer

Ambiguious column refernce in Union All

I am receiving an error message with my union all indicating that member_key is ambiguous. Adding an alias does not seem to resolve this. Any suggestions? proc sql; Select distinct member_key into: member_ky_list separated by "," From( select…
kim
  • 11
  • 1
1
vote
1 answer

How to multiply and merge two tables in SAS using a bridge table?

I am trying to merge two SAS tables based on a third “bridge table” and perform some calculations during the process. The code should be like “For each good lookup the price and calculate the annual revenue.” My raw data: one table with annual…
chris
  • 13
  • 2
1
vote
3 answers

proc rank in sas

my data set has two variables ID and diagnosis. I am trying to assign row numbers in my dataset based on ID and diagnosis. the code that I used was; proc sort data = temp; by ID diagnosis; run; proc rank data = temp out = temp1; by id; var…
Nupur
  • 347
  • 8
  • 19
  • 36
1
vote
3 answers

Stop SAS from counting blank cells with COUNT function

I am writing a SAS query to QA some data views. Part of the QA is determining what percentage of the values are populated. Unfortunately SAS is counting empty character cells as populated rather than NULL or having no data. For example, an ID field…
D_man
  • 113
  • 3
  • 9
1
vote
1 answer

Grouping range columns in SAS EG

I'm importing data into SAS that is divided into columns by monetary value. The data in the columns is a count of how many people fit into that category. Income_0-50K Income_50-100K Income_100K+ 5 10 5 Once imported, I'd…
Alice Wang
  • 29
  • 4
1
vote
1 answer

Subsetting Data Using Proc SQL

I am fairly new to SAS and am working on a sorting exercise to improve my SAS skills, but I seem to keep getting stuck since this dataset has observations with different date ranges. I was given generated admission and discharge data for patients…
Student
  • 61
  • 4
1
vote
2 answers

Recreate Tableau function FIXED in SAS proc SQL

I am working to shift calculations being performed in Tableau to be performed in an underlying SAS query and I am having a hard time recreating the Tableau Level of Detail function FIXED. Here's an example: { FIXED [ID_Field], [Group]:…
D_man
  • 113
  • 3
  • 9
1
vote
1 answer

SAS PROC SQL where between 4 mondays ago and last monday

I am trying to sum up the past 4 weeks forecast vs sales data with each week starting on a monday. For reference today is 8/6 so i want to start collecting their weekly sales and forecast for 7/5 going up until previous week monday, 7/26. I…
1
vote
1 answer

Query for a financial balance with a PROC SQL in SAS?

I have two tables, first call it "transactions" transaction_id transaction_type amount 101 1 50.00 102 2 25.00 103 3 35.00 104 2 15.00 105 1 60.00 and second call it…
1
vote
1 answer

Select the onset date of a disease based on the number of visits

I have data on physician visits for an infection. Individuals can have 1+ visits. Clinicians consider an individual is infected if he has more than one visit within a year. Then, the date of the first visit is considered as infection onset. For…
kiabar
  • 63
  • 6
1
vote
1 answer

SQL: How to group data while concating records of one colum

I have following problem: My data is ungrouped in the form of productid category attribute attributvalue product1 cat A length 20cm product2 cat A length 40cm product3 cat A width 20cm product4 cat B length 30cm I want to have the…
Tschou99
  • 13
  • 3