SQL procedures in SAS can organize data, data merging, and data selection functions.
SQL procedures can stitch two datasets, create tables, delete rows and columns in a table, and simply calculate individual variable values.
For example:
Proc SQL;
CREATE VIEW Work.body AS//select the variable id,de,age,sex from the ad table and add a variable height and a new table body
Select id, DE, age,sex,id**2\age as height//
From Work.ad//You can also merge two tables here, plus two tables from the back
where sex= ' Male ' id>20; Pick the male and id>20 data from the table variable sex
Order by ID;//Sort ID
Proc Print data=body; Print data body named body
Title ' Body ';
Run
That body is the newly created table
1.2 Features of the SQL process step
SQL procedure step does not need to repeat each query, each statement is processed separately, does not need print process step to print out the results of the query, do not use the sort process step to sort, do not need to run, to quit to end the SQL procedure step
1.3 SQL Procedure Step statement
SELECT: Querying data in a data table
ALTER: Add, delete, or modify columns of a data table
Create: Creating a data table
Delete: Remove columns from a data table
DESCRIBE: List The properties of a data table
Drop: Delete a data table, view, or index
Insert: Inserting data into a data table
RESET: No use, no idea what it means.
Select: Choose columns for printing
UPDATE: Modify the value of a column for an existing dataset
2 SQL basic Query function
2.1 SELECT statement Basic Syntax Introduction
SELECT <DISTINCT> Object-item <, ...object-item>
From From-list
<where sql-expression>
<group by Group-by-item <, ... group-by-item>>
<order by Order-by-item <, ... order-by-item>>;
Here Select: Specifies the selected column
From: Specifies the name of the table being queried
WHERE: Conditions for a child dataset
GROUP BY: Classify datasets by group
Having: A subset of data from a group by variable
ORDER BY: Sort the data set
SQL basic syntax in SAS