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

Changing SAS variable labels/attributes in one dataset based on variables in a separate dataset containing a codebook - PROC SQL? PROC DATASETS?

The core of my question is - can I use PROC SQL, PROC DATASETS or some other command to directly modify meta data of one data set, based on data in another dataset? If yes, can you tell me more about what code to use or what search terms to use in…
L.S.
  • 49
  • 6
2
votes
2 answers

How to join two databases using proc sql using two variables

I am trying to join two datasets based on variables office_id and office_id_flag, each with 50,000 observations. data1 variables grp age hispanic id race sex mental_ill mental_ill_dx office_id office_id_flag data2…
rlybby
  • 21
  • 1
2
votes
3 answers

I need a way to find if a row has a value, and if so then I need to group all rows based on another value

I need a way to check to see if a value is found e.g., 'Error', and if found then I need to group based on another value. I need to look for Value 3 and if value 3 is found then I need to group and tag all the rows with the same ID and Value1. Note:…
user13576801
2
votes
1 answer

SAS Proc SQL - ranking top nth (3rd) highest for a group of say universities and their price? (HW to be honest)

(this is homework, not going to lie) I have an ANSI SQL query I wrote this produces the required 3rd highest prices correctly, table sample is select unique uni, price from ( ( select unique uni, price from ( select unique…
Ray Man
  • 65
  • 11
2
votes
4 answers

PROC SQL - Transposing Data into Columns when Condition Met

My data is structured as below, where each unique ID will have a row displaying the balance on the last day of the month : ID Day_Key Balance 23412 20171229 50000 23412 20180131 45000 23412 20180228 40000 27435 20171229 …
ScottCee
  • 159
  • 11
2
votes
4 answers

List Aggregation and Group Concatenation in SAS Proc SQL

I have a dataset which has to be rolled up based on the granularity(FIELD1 & FIELD2). Two of the metrics fields(METRIC1 & METRIC2) have to be summed up. Until now it seems to be an easy GROUP BY task. But I have a string field(FLAG) which has to be…
Jonathan
  • 144
  • 4
  • 13
2
votes
1 answer

SAS: Improve efficiency of a cross join

In my project I am combining three unique input sources to generate one score. Imagine this formula Integrated score = weight_1 * Score_1 + weight_2 * Score_2 + weight_3 * Score_3 So, to do this, I have utilised the following code DATA…
78282219
  • 85
  • 1
  • 8
2
votes
2 answers

Parallel Processing in SAS

oh wise StackOverflow users. I have a question about parallel processing in SAS 9.4: I'm aware that SAS typically executes procedures in a sequential, or linear manner, however, I am also aware that SAS is capable of executing procedures in parallel…
2
votes
4 answers

Create several SAS macro variable lists from single dataset

Since the the length of the value of a macro variable cannot exceed the maximum length of (65534), I can't create a single macro variable for all of my observations. I would like to create a macro to iterate through my data set to generate several…
2
votes
4 answers

Convert values "Good" and "Bad" to boolean in order to calculate percentage (i.e, from all records, 80% were "Good") - Using SQL

Let's say I have a sample data set, p1, where different users have rated 4 different types of food, like so: Food_ID Rating 1 Good 1 Good 2 Good 2 Bad 1 Bad 3 Bad 3 Good 4 Bad 1 Bad 4 …
Tester_Y
  • 367
  • 4
  • 18
2
votes
2 answers

Adding label to SAS variables

I have a dataset in SAS called "Flight" and i want to label all the rows of one particular column "Carrier" with values which matches ("Flght_carrier_code") from another dataset called "Airlines". Please suggest some method. Sample Data set 1 -…
Aman kashyap
  • 143
  • 1
  • 3
  • 12
2
votes
2 answers

SAS proc sql inner join without duplicates

I am struggling to join two table without creating duplicate rows using proc sql ( not sure if any other method is more efficient). Inner join is on: datepart(table1.date)=datepart(table2.date) AND tag=tag AND ID=ID I think the problem is date and…
anna
  • 137
  • 7
2
votes
2 answers

Replace missing values in SAS by Specific Condition

I have a large dataset named Planes with missing values in Arrival Delays(Arr_Delay).I want to Replace those missing values by Average delay on the Specific route(Origin - Dest) by Specific Carrier. Hereby is the sample of the dataset : - date …
Aman kashyap
  • 143
  • 1
  • 3
  • 12
2
votes
1 answer

Splitting a Column into two based on condtions in Proc Sql ,SAS

I want to Split the airlines column into two groups and then Add each group 's amount for all clients... : - Group 1 = Air India & jet airways | Group 2 = Others. Loc Client_Name Airlines Amout BBI A_1ABC2 Air…
Aman kashyap
  • 143
  • 1
  • 3
  • 12
2
votes
2 answers

How to limit number of Months in SAS

I have one column name "month" which has 31 months what I want to do is I want to limit the number of months for example:- Current Month followed by two future months and 3 previous months followed by current month Like if the current month is April…
ASH
  • 41
  • 1
  • 1
  • 8