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

Extracting Minimum value after subsetting in PROC SQL

I have a sample dataset named Flights.I want to Extract from it the Origin Airport name which has least number of departure delays. Sample Flights data:- Date (Sched_dep_time) (dep_time)(flight)(origin) (Dep_delay_min) 01-01-2013 5:15 …
Aman kashyap
  • 143
  • 1
  • 3
  • 12
1
vote
1 answer

SAS PROC SQL: How to add trailing spaces?

I have a problem like this at work: Some system requires a specific input like: 0000051420189999999 ABC12345678<20 SPACES>; Which is a (some digit) + Sample_Date + (some digit) + x amount of spaces + Sample_KEY + y amount of…
George
  • 4,514
  • 17
  • 54
  • 81
1
vote
3 answers

SAS PROC SQL Group by all variables to detect duplicates

I have a dataset that contains 250 variables. I think some rows may be exact duplicates. If I only had 3 variables, I could run this code to check for dupes: proc sql; create table checkDupe as select count(*) as N, * from bigTable group by…
hossibley
  • 253
  • 5
  • 11
1
vote
1 answer

How to calculated median with weights using SAS proc sql?

To calculate the mean of variable "value" with weight, we can simply do the following: proc sql; select sum(Value*Weight)/sum(Weight) as WeightedAverage from table ; quit; How can we calculate median of the variable "value" with weight? I know we…
user2759430
  • 61
  • 2
  • 3
  • 9
1
vote
2 answers

How to find email domains using proc sql

In mysql this would look like: substring_index(email, '@', -1) But I can't seem to find if a function like this is available in SAS proc sql.
max
  • 671
  • 5
  • 13
1
vote
1 answer

Group by a formatted variable in PROC SQL

I am trying to group by custom formatted variable in PROC SQL, but so far have not found a solution. The log has no errors (like a summary statistic error here) and all code is valid. Here's a simple example: DATA have; INPUT value1; …
cacti5
  • 2,006
  • 2
  • 25
  • 33
1
vote
1 answer

Left Join collapses data

I am working with some bonds data and I'm looking to left join the interest rate projections. my data set for the bonds date looks like: data have; input ID Vintage Reference_Rate Base2017; Datalines; 1 2017 LIBOR_001M 0.01 1 2018 …
78282219
  • 593
  • 5
  • 21
1
vote
1 answer

Proc SQL : Expecting a name , Case When, End AS

While running the code mentioned below, I'm getting the error "ERROR 22-322: Expecting a name." and the affected code is 'END AS "Z"'. I'm not sure where I'm going wrong with this. proc sql; SELECT CASE WHEN REGION IS NULL THEN ZONE ELSE…
sklal
  • 175
  • 3
  • 15
1
vote
1 answer

Rollup function in SAS

I would like to add summary record after each group of records connected with specific shop. So, I have this: Shop_id Trans_id Count 1 1 10 1 2 23 1 3 12 2 1 8 2 …
max04
  • 5,315
  • 3
  • 13
  • 21
1
vote
1 answer

FCMP function giving unexpected results in PROC SQL

I wanted to take Rick Wicklin's macro (https://blogs.sas.com/content/iml/2015/10/05/random-integers-sas.html) that generates random numbers and convert it into an FCMP function. The FCMP function works as expected when called using…
Robert Penridge
  • 8,424
  • 2
  • 34
  • 55
1
vote
2 answers

Convert Month_Dt In sas

I have a sample data in this format as char. Month 2008-09 2007-10 2008-09 How to get the above as date '01sep2008' (SAS DESIGN STUDIO)
1
vote
1 answer

SAS: convert a character variable to numeric, keep all 0's if the input has some fields with only 0's

Objective: convert a character variable to numeric with proc sql in sas Conditions: The input variable has x lenght must keep all 0's in each position THERE ARE SOME FIELDS OF ONLY 0'S Ex: The table has one variable with the…
Rhein Romer
  • 13
  • 1
  • 3
1
vote
2 answers

SAS - PROC SQL - Sum values into unique columns

Simplifying the description of my table to keep my question concise... I have a data set with 3 columns. The first column contains 100 cost categories (i.e. unique key) and second column contains cost for the given cost category, the third contains…
1
vote
1 answer

Fuzzy match in proc sql, select minimum distance

I have a list with some fuzzy variables and a list with some clean variables. I want to want to (fuzzy) match both of them where the compged distance is lowest and some rules regarding their edit distances are satisfied (f.ex. compged < 100 and…
banan
  • 71
  • 6
1
vote
1 answer

Force all coefficients to be negative in PROC REG

I'm wondering if there's a way to force all non-intercept coefficients to be positive/negative in proc reg. If I use: model depvar=indvar; RESTRICT indvar<0; Then I always get a syntax error. Looks like Proc reg only supports equations and not…
johnv
  • 99
  • 1
  • 2
  • 7