Creating Character Variables II
Creating character variables in SAS generally requires a little more attention.
When using the Input statement, SAS assumes all of the variables to be numeric (unless specified otherwise).
Example
Data Test;
Input Name Gender Age;
Datalines;
John Male 31
Mary Female 22
Mark Male 45
;
Run;
The NAME and GENDER variable contain character values. However, they are not captured in the data set created.
(Try it!)
To create the character variables properly, you must add the dollar sign ($) in the Input statement after each character variables:
Example
Data Test;
Input Name $ Gender $ Age;
Datalines;
John Male 31
Mary Female 22
Mark Male 45
;
Run;
The dollar sign ($) tells SAS to create NAME and GENDER as character variables.
Exercise
Create a data set that contains the following variables:
Name the data set as PROFILE.
Need some help?
HINT:
Simply add the dollar sign ($) AFTER each character variables and you should be able to create the correct data set.
SOLUTION:
Data Profile;
Input PAT_ID $ Enrol $ BScore;
Datalines;
P001 Yes 99
P002 Yes 101
P003 No 125
;
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. |