Introduction to SAS [9-19]

h

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.

💪 Sign up for a free SASCrunch account now and keep track of your learning progress!


Exercise

Create a data set that contains the following variables:

Name the data set as PROFILE.

Need some help?

Get Hint

Get Solution