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

How to concatenate some elements in sql

I got a problem in SQL, I did a lot of request and now I want concatenate my first and last line on some specifics elements. Here a perfect example: id enter_date exit_date money 1 02/02/2020 28/02/2020 200$ 1 28/02/2020 …
seb
  • 7
  • 5
1
vote
2 answers

SAS EG (SQL) deleting rows where max value in one column

I need to delete all the rows with a max value of duty_perd_id where the rotn_prng_nbr and empl_nbr are the same (not the same to each other, but the max where of all of the rows where those two remain constant). From the table below it should…
1
vote
1 answer

SQL: Is it possible to replace values in an existing variable and rename it to the same name in the same SELECT statement?

I am wondering if it is possible to replace values in an existing variable in the same SELECT statement in SQL. create table temp as select ID , DOB , AGE , DISEASE_INDICATOR , case when…
ble9245
  • 15
  • 4
1
vote
1 answer

Joining Together Tables in PROC SQL

I want to join two tables that I created into one table but I am getting a syntax error that says Column OverallStudentReport.ID was found in more than one table in the same scope. If anyone could help fix this syntax error that would be appreciated…
Nan
  • 61
  • 4
1
vote
1 answer

How to use a value that comes from a different table?

I created a dataset to calculate a threshold: Data black; Set blue; Lower=p20-2; Upper=p20+2; Run; I would like to use this value the output is something like: Variables n lower upper Val 123 -0.2 0.1 I would like to use upper and lower as…
LdM
  • 674
  • 7
  • 23
1
vote
2 answers

Removing rows that happened within two days of a date

me again. It's a bit tricky to explain this, but I'll try my best. I have a dataset that contains customer ID's, days in which those customers were called and a dummy column when 1 is when we talked to a person and 0 is when we didn't. data…
amestrian
  • 546
  • 3
  • 12
1
vote
4 answers

"case when" going wrong

I want to create a column "Cured" that takes value 1 when the customer left have1 either on the day or in the two following days after appearing in have2. Data have1 is a dataset that defines when a client entered and left certain status. have2…
amestrian
  • 546
  • 3
  • 12
1
vote
2 answers

Create variable that counts progressively how many times an ID is repeated in a day

So I have a table that has different days and didfferent hours in each day, and the client ID can appear multiple times per day. data Data1; infile datalines delimiter=','; input date :ddmmyy10. ID $ time :time8. $ ; format date ddmmyy10.; …
amestrian
  • 546
  • 3
  • 12
1
vote
1 answer

PROC SQL: CASE WHEN EXPRESSION - Result of WHEN clause 2 is not the same data type as the preceding results

I'm trying to create and fill a column: 'FLAG' ,using data from two tables: carteira_base30 and TRIGGERS_21. Whenever carteira_base30.Data_ref is 31DEC2015 (format: DATE9.) it should retrieve info from TRIGGERS_21.D31DEC2015 (column in number format…
1
vote
2 answers

Change the length of a variable in IMPALA SQL Select statement through SAS

I am connecting to an impala server to retrieve some data. However I want to change the length of the variable in the impala pass-through sql statement because otherwise it will retrieve the variable with a length of 32767 which is not…
Kermit
  • 3,112
  • 2
  • 10
  • 34
1
vote
2 answers

Calculate average of the last x years

I have the following data Date value_idx 2002-01-31 . 2002-01-31 24.533 2002-01-31 26.50 2018-02-28 25.2124 2019-09-12 22.251 2019-01-31 24.214 2019-05-21 25.241 2019-05-21 . 2020-05-21 25.241 2020-05-21 23.232 I would…
user14289862
1
vote
1 answer

SAS Same column selection multiple times using multiple where clause as different output columns

I have a temp table that is being created, we will say that column 1 is YearMonth, column2 as user_id, Column 3 is flag1, column 4 is flag. YearMonth User_id Flag1 Flag2 200101 1 N N 200101 2 N N 200101 3 …
user11505060
1
vote
1 answer

how to join two datasets and update one column values only not affects other columns in sas?

this is a sample datasets need to be update one columns only .same columns name but different values add only like age in first ds. data step or proc sql; common values dob and name Please help me thanks first data set data sql; input name $4. age…
1
vote
1 answer

Cumulative sum with proc-sql

I want to create a table "table_min_date_100d_per_country" which contains the first date where the cumulation by date of COVID cases exceeds 100 per country. I have the columns date, cas_covid, country. Sample data is.. Date Cas_covid …
Chafik Ahl
  • 11
  • 2
1
vote
1 answer

Concatenate macro variables in SAS to rename a column

I have some macro variables that I want to concatenate together to rename a column in a table. %let input_group = state; %let input_id = zip; data output; set output; rename var1= catx(_, &input_id, &input_group, '1'); run; In my output table I…
kroach
  • 25
  • 1
  • 5