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

create variable for unique sessions

I have some data about when, how long, and what channel people are listening to the radio. I need to make a variable called sessions that groups all entries which occur while the radio is on. Because the data may contain some errors I would like…
user2448666
  • 329
  • 1
  • 6
  • 14
0
votes
1 answer

dummy variable based on string

I want to search through a character variable, find all of the observations that have the word "internet" and insert a 1 into the dummy variable created for those observations. Really I just need help searching one column for a string, but I cant…
user2448666
  • 329
  • 1
  • 6
  • 14
0
votes
1 answer

creating a long list of new variables based on existing column

I need to create a variable for week0-week187 and doing that RBAR is just that. data looks like: ID WEEK 1 0 1 28 1 186 2 187 2 30 I am trying to make week0-week187 variables that will be 1 or 0 if the observation is in a given week, should…
user2448666
  • 329
  • 1
  • 6
  • 14
0
votes
3 answers

SAS Proc SQL Count Issue

I have one column of data and the column is named (Daily_Mileage). I have 15 different types of daily mileages and 250 rows. I want a separate count for each of the 15 daily mileages. I am using PROC SQL in SAS and it does not like the Cross join…
Sarah Reinke
  • 57
  • 3
  • 9
0
votes
2 answers

SAS - Select from multiple records with same id but different status

Sorry for the misleading (if there is) question title, as I don't know how to express what I need in 1 question. I have a dataset as below: UserId Order Status 1 1 completed 1 2 completed 1 3 …
Luke Henz
  • 137
  • 3
  • 5
  • 12
0
votes
2 answers

What is wrong with this SAS code?

I copy the code from a paper that i found on internet. proc fcmp outlib=work.funcs.Test; function whatAmI(); return(42); endsub; quit; options cmplib=work.funcs; data _null_; rci = whatAmI(); put rci=; /* should be 42…
Bruno
  • 1
  • 2
0
votes
2 answers

I'm trying to use case statement with looping inside a where clause of proc sql

I'm trying to create Stored process code for multilple prompt values in SAS EG...SO when I run stored process I want to give multiple values for Fac_Nm..... PROC SQL; CREATE TABLE rpt_fac_prd_schd AS select rpt.fac_id,fac.fac_nm as…
SAS_learner
  • 521
  • 1
  • 13
  • 30
0
votes
2 answers

Subqueries yielding more results then expected on join of two subsets

I'm receiving more ID's then possible after performing a left outer join statement on two tables. Context: I've narrowed down two tables from larger data sets. Below are the queries found I've used to obtain IDs possible after selecting from the…
coatless
  • 20,011
  • 13
  • 69
  • 84
-1
votes
2 answers

How to create 2 new columns with appropriate prefix based on values in columns with same prefix in SAS Enterprise Guide / PROC SQL?

I have table in SAS Enterprise Guide like below: ID | COUNT_COL_A | COUNT_COL_B | SUM_COL_A | SUM_COL_B -----|-------------|-------------|-----------|------------ 111 | 10 | 10 | 320 | 120 222 | 15 | 80 …
dingaro
  • 2,156
  • 9
  • 29
-1
votes
2 answers

How to get distinct fruits where indicator =only B and make sure that fruit listed is not coded on any "A" Indicator column in proc sql

How to get distinct fruits where indicator =only B and make sure that fruit listed is not coded on any "A" Indicator column. I tried this but obviously its not…
kfc123456
  • 1
  • 1
-1
votes
1 answer

Why does my GROUP BY statement in my subquery get ignored and give me duplicates?

I am using Proc SQL within SAS. When I use the GROUP BY statement in my main query, I get this error: NOTE: A GROUP BY clause has been discarded because neither the SELECT clause nor the optional HAVING clause of the associated table-expression…
-1
votes
1 answer

How to fill column using values in 2 other columns in PROC SQL / SAS code in SAS Enterprise Guide?

I have table in SAS Enterprise Guide like below: Data types: VAL1 - character ID - numeric VAL2 - character (with only 3 possible values: P, C, S) ID EVENT GRADE 123 NY P 123 NY P 123 NY S 55 MAD C 55 MAD S 55 LON S ID -…
unbik
  • 178
  • 9
-1
votes
1 answer

How to add/subtract weeks to the third day of the week?

I'm trying to figure out how to translate this line of PROC SQL code into Snowflake SQL but haven't found a way yet. %LET last_post_dt = %SYSFUNC(INTNX(WEEK.3,%SYSFUNC(TODAY(),),-2,B),DATE9.); Basically, its subtracting 2 weeks from the third day…
-1
votes
1 answer

Proc SQL left join with aggregate function omitting zeroes

I have two data sets in SAS 9.4. One is type_list, which contains 14 different account types. The other is account_list, which contains thousands of accounts. I'm trying to get a list of all types with a count of how many accounts in each type meet…
Dacromir
  • 186
  • 2
  • 11
-1
votes
2 answers

SQL count occurrences without counting duplicates in another column

I have a table: Date | ID | Company | Click -----------+----+---------+-------- 01/01/2021 | 01 | Us | 1 01/01/2021 | 01 | Us | 1 01/01/2021 | 01 | Other | 1 01/01/2021 | 02 | Us | 0 01/01/2021 | 02 | Other | 0 02/01/2021…
amestrian
  • 546
  • 3
  • 12