Writing First code in SAS Part 2
Welcome back to Mindful Data Minds! In the previous session, we learned how to create a dataset using the SAS Data Step. In this session, we’ll go deeper into data types and learn how to calculate values inside a SAS Data Step.
Watch the Full Tutorial
What You Will Learn
- The two main data types in SAS (character and numeric).
- How SAS stores dates as numbers with formats.
- How to check data types using alignment or properties.
- How to create calculated columns using arithmetic.
- How to add default numeric or character columns.
SAS Data Types
In SAS, every variable (or column) belongs to one of two types:
- Character → Text values (like names or regions).
- Numeric → Numbers (like sales, returns, or dates).
Example:
- Region is a character type.
- Sales is a numeric type.
Dates in SAS
- Dates are stored as numeric values (similar to Excel).
- For example, the number
3500represents 31st July 1909. - SAS applies a date format to show the number as a readable date.
💡Quick Tip
- Character values are left-aligned.
- Numeric values are right-aligned.
- You can also check the Properties tab in SAS Studio to see the data type, length, format, and labels.
Creating Calculated Columns
You can create new columns in your dataset by performing calculations.
data a;
set sashelp.shoes;
exact = sales - returns;
run;
- This creates a new column called exact.
- It subtracts Return from Sales for each row.
- The result is stored as a numeric type.
Adding Default Columns
You can also add new columns with default values.
Numeric Column
column1 = 252;
This adds a column named column1 with the value 252 for every row.
Character Column
column2='char type';
This adds a column named column2 with the text "char type" for every row.
Next Step
Continue learning by exploring the next tutorial in this series. Also subscribe to get notified about new lessons.
Have a Question?
Drop your doubts in the comments below or contact us.
