Previous Page | Next Page

Working with Character Variables

Input SAS Data Set for Examples

Tradewinds Travel has an external file with data on flight schedules for tours.

The following DATA step reads the information and stores it in a data set named AIR.DEPARTURES:

options pagesize=60 linesize=80 pageno=1 nodate;
libname mylib 'permanent-data-library';

data mylib.departures;
   input Country $ 1-9 CitiesInTour 11-12 USGate $ 14-26 
         ArrivalDepartureGates $ 28-48;
   datalines;
1           2   3               4 
Japan      5 San Francisco          Tokyo, Osaka
Italy      8 New York               Rome, Naples
Australia 12 Honolulu           Sydney, Brisbane
Venezuela  4 Miami            Caracas, Maracaibo
Brazil     4               Rio de Janeiro, Belem
;
proc print data=mylib.departures;
   title 'Data Set AIR.DEPARTURES';
run;

The numbered fields represent

[1] the name of the country toured

[2] the number of cities in the tour

[3] the city from which the tour leaves the United States (the gateway city)

[4] the cities of arrival and departure in the destination country

The PROC PRINT statement that follows the DATA step produces this display of the AIR.DEPARTURES data set:

Data Set AIR.DEPARTURES

                            Data Set AIR.DEPARTURES                            1

                          Cities
      Obs    Country      InTour    USGate           ArrivalDepartureGates

       1     Japan           5      San Francisco    Tokyo, Osaka         
       2     Italy           8      New York         Rome, Naples         
       3     Australia      12      Honolulu         Sydney, Brisbane     
       4     Venezuela       4      Miami            Caracas, Maracaibo   
       5     Brazil          4                       Rio de Janeiro, Belem

In AIR.DEPARTURES, the variables Country, USGate, and ArrivalDepartureGates contain information other than numbers, so they must be stored as character variables. The variable CitiesInTour contains only numbers; therefore, it can be created and stored as either a character or numeric variable.

Previous Page | Next Page | Top of Page