This will help you to create or modify a variable. It is common to define a new variable based on the existing variable.
Let’s create a dataset
In the code below, we are creating a dataset named as Example1 which is going to store on WORK(temporary) library. In this dataset, there would be a variable called OldRate which contains a numeric value. The RUN statement is defined to close the dataset program.
Creating a numeric variable
You can create variables using the form: variable = expression;
Suppose you are asked to create a new variable NewRate, in the existing SAS data set Example1. Both variables are numeric. The variable NewRate is twice of OldRate.
If you are asked to store a new variable NewRate on a new dataset, you can create it using DATA statement.
In above case, the dataset READIN was created.
- Creating a character variable
In the dataset Example1, let’s create a character variable as Type. The character value for the set is set ‘GeeksforGeeks’.
The quote marks need to be entered around the character variable.
Since Type is a character variable, so the value entered should in quotes. It can be either single or double quotes.
Creating or Modifying a variable
Suppose the value of OldRate is increased by 8 units and you need to calculate the relative change in rate. In this case, we are modifying the existing variable OldRate so we will add 8 to OldRate. later we calculate the percentage change between old and new rate.
OldRate=8 + OldRate;
Change= ((NewRate-OldRate)/ OldRate);
Format Change Percent10.0;
The FORMAT statement is used to display the changed value in percentage format.
- Introduction to SAS programming
- How to import External Data from Excel or Text file into SAS Programming?
- Contains and Between-And operators in SAS Programming
- How to drop variables from a dataset in SAS Programming?
- Where Statement in SAS Programming
- If-Then-Else statement in SAS Programming
- IS MISSING and IS NOT MISSING Operators in SAS Programming
- Like Operator in SAS Programming
- How to import data into SAS?
- SAS | How to specify a list of Variables?
- SAS | How to read character of varying length using COLON Modifier
- SAS | How to read character using Ampersand(&)
- SAS | Date Formats and Informats
- SAS | Delete Empty Rows
- SAS | COALESCE Function with Examples
- SAS : How to Display Current Date?
- SAS | COMPRESS Function with Examples
- Modify values of a Data Frame in R Language - transform() Function
- How to load and modify matrices and vectors in Octave?
- Difference between Functional Programming and Object Oriented Programming
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.