Creating Character Variables
Unlike other programming languages such as R, Java or C++, there are only 2 types of variable in SAS:
Numeric and Character
Creating a character variable is easy. You simply need to enclose them with a quotation mark.
Either single quotation ('John') or double quotation ("John") works.
Example
Data Test;
Name = "John";
Class = "Mathematics";
Run;
This DATA Step will create two character variables: Name and Class. They both contain character values.
(Try it!)
Tips: If you have the TEST data set opened while running the code, the data set will not get updated.
Exercise
Create a data set that contains the following variables:
Restaurant: Burger King
NumEmploy: 5
Location: Toronto
Name the data set as Food.
Need some help?
[learndash-topic-after]
test
[/learndash-topic-after]
Need some help?
HINT:
Make sure you enclose the character data in quotation.
SOLUTION:
Data Food;
Restaurant = "Burger King";
NumEmploy = 5;
Location = "Toronto";
Run;
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |