How to Hardcode a Dataset in SAS: A Beginner’s Guide to DATALINES
If you’re just starting out with SAS, you might think you always need to import data from a file. But did you know you can manually create your own dataset directly in your code? It’s a super useful skill for testing, learning, and building examples without needing any files.
In this guide, I’ll show you how to hardcode a dataset in SAS using a simple DATA
step and DATALINES
.
Why Would You Hardcode Data?
Manually creating a dataset in your code can be helpful when:
- You want to test your SAS code with a small set of data.
- You’re learning and just want a quick way to practice.
- You want to build an example without uploading a file.
- You’re writing tutorials or documentation.
How to Hardcode a Dataset Using DATALINES
Here’s an easy example of how to create a dataset with customer information:

What’s Happening Here?
Let’s break it down:
data Customer_Info;
tells SAS to create a dataset calledCustomer_Info
.input
lists the column names and types. Use$
after a name if it’s a text (character) variable.datalines;
starts the section where you type your data directly.- Each line represents one row of data.
run;
finishes the data step.

When Should You Use This?
Use hardcoded data when:
- You’re practicing SAS syntax.
- You want to test something quickly.
- You need a small example to share with a friend or colleague.
When NOT to Use It
Avoid hardcoding when:
- You have a large dataset (it gets messy fast!).
- If the data changes often, then you’ll have to update it by hand.
- You’re building something for production or regular use.
Final Thoughts
Manually creating datasets is a great beginner skill. It helps you practice SAS faster, test ideas, and build your confidence. As you keep learning, you’ll start working with real data files, but hardcoding will still come in handy for quick demos and testing.