BookmarkSubscribeRSS Feed

A Beginners Guide to Using Arrays and DO Loops

Started ‎07-06-2020 by
Modified ‎07-07-2020 by
Views 4,113

If you're copying and pasting code over and over to perform the same operation on multiple variables in a SAS DATA step, you need to learn about arrays and DO loops. Arrays and DO loops are efficient and powerful data manipulation tools that belong in your programmer’s toolbox. In this 20-minute workshop, you'll learn how to create an array and use DO loops to perform operations on the elements in an array, create new variables, and change a short and wide data structure to a long and skinny one.

 

 

 

 

 

Video highlights

00:40 - What is an array?

01:22 - What is a DO loop?

04:47 - Syntax of an array

05:34 - For indexed array, indicate number of elements in curly brackets

05:49 - Character variables? Designate array with dollar sign

06:00 - Other options for variables

08:12 - Start with array statement, end with semicolon

11:46 - How to reference an array in an interative DO loop or indexed DO loop

15:19 - Example of a do-over loop with a non-indexed array

 

Read the Paper

Related resources

GitHub materials

How to Restructure Your Data Using Arrays and DO Loops (YouTube tutorial)

 

Contributors
Version history
Last update:
‎07-07-2020 03:52 PM
Updated by:

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Tags