Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

SAS basic syntax


May 26, 2021 SAS


Table of contents


Like any other programming language, the SAS language has its own syntax rules to create SAS programs. T he three components of any SAS scenario - declarations, variables, and datasets - follow the following syntax rules.

SAS statement

  • Statements can start and end anywhere. T he sign at the end of the last line marks the end of the statement.
  • Many SAS statements can end each statement with a half sign on the same line.
  • Space can be used to separate components in SAS program statements.
  • SaS keywords are case insenso sensitive.
  • Each SAS program must end with a run statement.

The name of the SAS variable

The variables in the SAS represent a column in the SAS dataset. T he variable name follows the following rules.

  • It can have up to 32 characters.
  • It cannot contain spaces.
  • It must start with the letters A to Z (case insensication) or underscores.
  • Numbers can be included, but not as the first character.
  • The variable name is case insenso sensitive.

Cases

# Valid Variable Names
REVENUE_YEAR
MaxVal
_Length

# Invalid variable Names
Miles Per Liter	#contains Space.
RainfFall%      # contains special character other than underscore.
90_high		# Starts with a number.

SAS dataset

The DATA statement tag creates a new SAS dataset. The rules for creating a DATA set are as follows.

  • A word after the DATA statement represents the name of a temporary dataset. T his means that the dataset is deleted at the end of the session.
  • The dataset name can be prefixed with the library name, which makes it a permanent dataset. T his means that the dataset still exists after the session ends.
  • If the SAS dataset name is omitted, SAS creates a temporary dataset that contains names generated by SAS, such as - DATA1, DATA2, and so on.

Cases

# Temporary data sets.
DATA TempData;
DATA abc;
DATA newdat;

# Permanent data sets.
DATA LIBRARY1.DATA1
DATA MYLIB.newdat;

SAS file extension

The results of SAS programs, data files, and programs are saved in Windows with various extensions.

  • .sas - It represents an SAS code file that can be edited using the SAS editor or any text editor.
  • :: .log - It represents the SAS log file, which contains errors, warnings and data set details for the submitted SAS program.
  • :: .mht / .html - it represents the SAS results file.
  • .sas7bdat - It represents an SAS data file that contains the SAS dataset, including variable names, labels, and calculations.

Comments in SAS

Comments in SAS code are specified in two ways. T he following are the two formats.

Information; The type of comment

Comments in the form of messages; Y ou cannot include a sign or mismatched quotation marks in it. A dditionally, there should be no reference to any macro statements in such comments. I t can span multiple lines and can be of any length: H ere's an example of a one-line comment:

* This is comment ;

Here's an example of a multi-line comment:

* This is first line of the comment
* This is second line of the comment;

/ s message s / type comments

Comments in the form of / messages are used more frequently and cannot be nested. B ut it can span multiple lines and can be any length. H ere's an example of a one-line review:

/* This is comment */

Here's an example of a multi-line comment:

/* This is first line of the comment
* This is second line of the comment */