Data Science Examples

Data Science Code Example“Know your data”. A tired, old phrase you have probably heard a million times before. Nevertheless, it is very important. Especially in SAS programming. Having a clear view of what your data looks like is essential, regardless of what you want to do with it. You should familiarize yourself with the data you work with. For this purpose, SAS procedures like PROC DATASETS, PROC CONTENTS and PROC COMPARE are invaluable. Many of the examples below take advantage of the numerous features of these procedures.

However, it is not enough to familiarize yourself with what the data looks like now. It is equally important to know how to reshape it. Different tasks in SAS require different datashapes. Therefore, it is important to know how to manipulate datasets efficiently. You should know what tool to use when.

The data step and the various available procedures makes virtually any data manipulation task possible. On this page, I present code examples of common issues and how to solve them efficiently in SAS.

Data Science SAS Code Examples

Add Leading Zeros to Numeric Variable in SAS

Remove Duplicate Values

Drop or Keep Variables with Same Suffix

Delete All Data Sets in a Library

Copy and Move Data Sets Between Libraries

Check If Two Data Sets Are Identical

Reverse the Order in a Data Set

Check Available Memory To SAS Session

Check if SAS Data Set Exists in Library

Find Number of Observations in a SAS Data Step

A Simple Proc Tabulate Example in SAS

A Simple Proc Summary Example in SAS

Proc Datasets Simple Examples in SAS

Proc Datasets Simple Examples in SAS

Generate Random Number Between 1 and 10 in SAS

Learning the basics of how to manipulate datasets is fundamental for almost everything else in SAS. If you do not know how to shape and manipulate your data, you will have a hard time doing statistical analysis, graphing, or what you might think of doing in your SAS code. The Data Step is an essential part of this. For a great introduction to data step processing and much more, I encourage you to take the Programming 1 E-Learning Course provided for free by SAS Institute. For other learning materials, see my Learn SAS Programming page.

Finally, I have a few related examples on my blog as well. See them all in the Data Category.