Serge Kashlik
Serge Kashlik

Reputation: 413

How to maually input data in SAS EG

Just started learning SAS and am going through a textbook where a table is created using the following code.

Data travel;
    input City $ 1-9 Nights 11 LandCost 13-16 NumberOfEvents 18
          EventDescription $ 20-36 TourGuide $ 38-45
          BackUpGuide $ 47-54;
datalines;
Rome        3 750   7 4 M, 3 G                  D’Amico Torres
Paris       8 1680  6 5 M, 1 other              Lucas Lucas
London      6 1230  5 3 M, 2 G                  Wilson Lucas
New York    6 .     8 5 M, 1 G, 2 other         Lucas D’Amico
Madrid      3 370   5 3 M, 2 other              Torres D’Amico
Amsterdam   4 580   6 3 M, 3 G                  Vandever
;
Run;

The book gives this as the expected output:

However when I run the program it gives me the following
enter image description here

How can this be fixed? enter image description here

Upvotes: 1

Views: 92

Answers (2)

Richard
Richard

Reputation: 27498

How did you enter the data lines them selves ?

If you typed them in with an editor having a tab-stop set to 4 AND you used some tabbing during keying in the datalines it is possible those stops caused the data to be misaligned with the sample code.

If you copy pasted, perhaps the source had tabs and the editor expanded the tabs to spaces that reached the tab stops.

Regardless, adding a 'ruler' comment line can help you see what adjustments need to be made to the code or the data lines.

Data travel;
    input City $ 1-9 Nights 11 LandCost 13-16 NumberOfEvents 18
          EventDescription $ 20-36 TourGuide $ 38-45
          BackUpGuide $ 47-54;
datalines;
Rome        3 750   7 4 M, 3 G                  D’Amico Torres
Paris       8 1680  6 5 M, 1 other              Lucas Lucas
London      6 1230  5 3 M, 2 G                  Wilson Lucas
New York    6 .     8 5 M, 1 G, 2 other         Lucas D’Amico
Madrid      3 370   5 3 M, 2 other              Torres D’Amico
Amsterdam   4 580   6 3 M, 3 G                  Vandever
;
*234567890123456789012345678901234567890123456789012345678901234567890123
*        1         2         3         4         5         6         7
*   T   T   T   T   T   T   T   T   T   T   T   T   T   T   T   T   T   T  cursor position after tab hit
;

<NOSTALGIA>

Some days I wax nostalgic for the Program Editor and line commands such as COLS

enter image description here

SAS documentation seems to be ridding itself of program editor documentation like an embarrassed adult might do of bad haircut pictures from their teenage years.

Good luck finding The COLS line command displays a special line that indicates the column numbers across the Program Editor window. at documentation.sas.com, I couldn't.

</NOSTALGIA>

Upvotes: 1

PeterClemmensen
PeterClemmensen

Reputation: 4937

Your column pointers are not correct. See if this helps you

Data travel;
    input City $ 1-9 Nights 11 LandCost 13-16 NumberOfEvents 18
          EventDescription $ 20-36 TourGuide $ 38-45
          BackUpGuide $ 47-54;
datalines;
Rome      3 750  7 4 M, 3 G          D’Amico  Torres 
Paris     8 1680 6 5 M, 1 other      Lucas    Lucas  
London    6 1230 5 3 M, 2 G          Wilson   Lucas  
New York  6 .    8 5 M, 1 G, 2 other Lucas    D’Amico
Madrid    3 370  5 3 M, 2 other      Torres   D’Amico
Amsterdam 4 580  6 3 M, 3 G          Vandever        
;
Run;

Upvotes: 0

Related Questions