How to Create Tables in SAS (With Examples)

Creating tables in SAS is a straightforward process. The DATA step is used to create a dataset which is then used to create a table. The PROC PRINT and PROC REPORT commands are used to produce summary tables, and the PROC TABULATE command can be used to create a variety of tabular reports. Examples of PROC PRINT, PROC REPORT, and PROC TABULATE commands are provided to illustrate their usage.


You can use proc sql to quickly create tables in SAS.

There are two ways to do so:

1. Create a Table from Scratch

2. Create a Table from Existing Data

The following examples show how to do both using proc sql.

Example 1: Create a Table from Scratch

The following code shows how to create a table with three columns using proc sql in SAS:

/*create empty table*/
proc sql;
   create table my_table
       (team char(10),
        points num,
        rebounds num);

/*insert values into table*/          
   insert into my_table
      values('Mavs', 99, 22)
      values('Hawks', 104, 20)
      values('Hornets', 88, 25)
      values('Lakers', 113, 19)
      values('Warriors', 109, 32);

/*display table*/
   select * from my_table;
run;

create table in SAS

We used create table to create an empty table, then used insert into to add values to the table, then used select * from to display the table.

The result is a table with three columns that show various information for different basketball teams.

Example 2: Create a Table from Existing Data

The following code shows how to use proc sql to create a table by using an existing dataset that we created in the previous example:

/*create table from existing datset*/
proc sql;
   create table my_table2 as
      select team as Team_Name,
             points as Points_Scored
         from my_table;
         
/*display table*/
   select * from my_table2;
run;

The result is a table that contains two columns with values that come from an existing dataset.

Note: We used the as function to specify the column names to be used in the table, but you don’t have to use the as function if you don’t want to rename the columns.

The following tutorials explain how to perform other common tasks in SAS:

x