SAS for Beginners…Part 2

Pratibha Singh
3 min readMar 20, 2021

Basic rules of SAS:

  1. Dataset names cannot start with number, it can only start with underscore “_” or a character.
  2. While typing the dataset name we cannot give space between if done so SAS will take both the words with space as two different data sets. Eg., “my demo” will result into two datasets named “my” and “demo”.
  3. Dataset name cannot have more than 32 characters.
  4. SAS is not case sensitive.
  5. Dataset can have its name ending or in middle as a numerical, this will not cause any problem.
  6. When we add data the columns to the dataset with character value, only 8 characters are read by SAS as a default method, to overcome this problem we need specify the max limit of characters to be read like “name$20”- then SAS will read up to 20 characters written in “name”; max can go upto 32767 characters.

Basics of SAS:

SAS programs are a combination of DATA steps and procedures (i.e. PROCs).

Data Steps: The DATA step consists of a group of SAS statements that begins with a DATA statement. The DATA statement begins the process of building a SAS data set and names the data set. The statements that make up the DATA step are compiled, and the syntax is checked. If the syntax is correct, then the statements are executed. In its simplest form, the DATA step is a loop with an automatic output and return action.

An example of the general syntax of a SAS DATA step:

DATA dataset_name; 
INPUT variable_names;
CARDS;
lines_of_data
;
RUN;

PROCs: Procedures come in many forms. They consist of the proc phrase followed by a set of sub-phrases particular to the procedure invoked. The proc phrase in its simplest form is simply (using the means procedure to illustrate)

proc print;

This automatically uses the data set from the previous proc or data step. The form

proc print data=a;

explicitly uses the data set a rather than the previously or created one. PROCs perform a wide variety of tasks and can be thought of as “pre-canned” routines. Tasks include the following (amongst many others):

  • Data management tasks (i.e. PROC APPEND, PROC IMPORT, PROC EXPORT)
  • Descriptive statistics (i.e. PROC UNIVARIATE, PROC MEANS)
  • Statistical modeling (i.e. PROC REG, PROC LOGISTIC)
  • Statistical inference (i.e. PROC TTEST)

In general, PROCs consist of an initial proc name, followed by options and sub-phrases specific to the proc name, and finally a RUN statement.

Below is an example of the general syntax of a SAS PROC:

PROC proc_name options; 
sub_phrases / options;
RUN;

SAS Variables

They are containers that we create within a program to store and use character and numeric values. Variables have attributes, such as name and type, that enable us to identify them and that define how they can be used.

Character variables: They are variables of type character that contain alphabetic characters, numeric digits 0 through 9, and other special characters.

Numeric variables: They are variables of type numeric that are stored as floating-point numbers, including dates and times.

Numeric precision: Refers to the degree of accuracy with which numeric variables are stored in our operating environment.

To be continued…

--

--