BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RaginiS
Fluorite | Level 6

Hi! I am practicing my basic SAS skills and need to know how to solve this very elementary error

 

I wrote this simple code and when I run it , SAS show errors. Please tell me how I can fix this?

My code

Title "BAS 150 First Program";

Data soccer_scores;

        Input player goals age years_played;

       

        datalines;

        Rachel 10 8 4

        Bobby 8 8 2

        Jodie 15 10 5

        Lori 5 7 2

        Danny 6 6 1

        Pat 7 5 1

        John 15 9 5

        Betty 12 10 3

        ;

        Run;

       

proc print data=scores;

    var player age goals;

    run;

 

ERROR LOG-

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

 72        

 73         Title "BAS 150 First Program";

 74         Data soccer_scores;

 75         Input player goals age years_played;

 76        

 77         datalines;

 

 NOTE: Invalid data for player in line 78 1-7.

 RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+

 

 78  CHAR   .Rachel 10 8 4                                                                 

     ZONE   05666662332323222222222222222222222222222222222222222222222222222222222222222222

     NUMR   921385C0100804000000000000000000000000000000000000000000000000000000000000000000

 player=. goals=10 age=8 years_played=4 _ERROR_=1 _N_=1

 NOTE: Invalid data for player in line 79 1-6.

 

 79  CHAR   .Bobby 8 8 2                                                                   

     ZONE   04666723232322222222222222222222222222222222222222222222222222222222222222222222

     NUMR   92F22908080200000000000000000000000000000000000000000000000000000000000000000000

 player=. goals=8 age=8 years_played=2 _ERROR_=1 _N_=2

 NOTE: Invalid data for player in line 80 1-6.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi: When you read data with an INPUT statement, one of the important pieces of information that needs to be determined is HOW to read the variable. By default, with an INPUT statement such as you have, you are telling SAS that ALL your values (after DATALINES) are numeric.

This presents SAS with a problem and the NOTE tells you exactly what the problem is:
"NOTE: Invalid data for player ..." SAS is trying to read "Rachel" from the first row and "Bobby" from the second row as numbers. That means you did not specify the correct method for reading the PLAYER value.

The typical indicator for reading a character value, with SAS, in an INPUT statement is to use a $ (dollar sign). There are a couple of different ways to read your data, but with list input, the easiest way is to read about the INPUT statement and look at some examples and see if you can figure out where a $ would belong in your INPUT statement to read PLAYER.

The default length for a character variable is 8 so if you KNOW that you only have names that are 8 bytes in length (or less) then you are OK with the default; however if you will have names longer than 8, then you might need a LENGTH statement.

Just a quick Google search revealed a nice example here:
http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a003209907.htm

for LIST input that shows you both the use of the $ and the use of the LENGTH statement.

Cynthia

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Post your code using the code editor to make it readable

 

Data soccer_scores;

        Input player $goals age years_played;

       

        datalines;
       Rachel 10 8 4
        Bobby 8 8 2
        Jodie 15 10 5
        Lori 5 7 2
        Danny 6 6 1
        Pat 7 5 1
        John 15 9 5
        Betty 12 10 3
        ;

        Run;

 

 

RaginiS
Fluorite | Level 6

Is this better?

 

Log: Program 1

 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 Title "BAS 150 First Program";
74 Data soccer_scores;
75 Input player goals age years_played;
76
77 datalines;
 
NOTE: Invalid data for player in line 78 1-7.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+
 
78 CHAR .Rachel 10 8 4
ZONE 05666662332323222222222222222222222222222222222222222222222222222222222222222222
NUMR 921385C0100804000000000000000000000000000000000000000000000000000000000000000000
player=. goals=10 age=8 years_played=4 _ERROR_=1 _N_=1
NOTE: Invalid data for player in line 79 1-6.
 
79 CHAR .Bobby 8 8 2
ZONE 04666723232322222222222222222222222222222222222222222222222222222222222222222222
NUMR 92F22908080200000000000000000000000000000000000000000000000000000000000000000000
player=. goals=8 age=8 years_played=2 _ERROR_=1 _N_=2
NOTE: Invalid data for player in line 80 1-6.
 
80 CHAR .Jodie 15 10 5
ZONE 04666623323323222222222222222222222222222222222222222222222222222222222222222222
NUMR 9AF49501501005000000000000000000000000000000000000000000000000000000000000000000
player=. goals=15 age=10 years_played=5 _ERROR_=1 _N_=3
NOTE: Invalid data for player in line 81 1-5.
 
81 CHAR .Lori 5 7 2
ZONE 04676232323222222222222222222222222222222222222222222222222222222222222222222222
NUMR 9CF29050702000000000000000000000000000000000000000000000000000000000000000000000
player=. goals=5 age=7 years_played=2 _ERROR_=1 _N_=4
NOTE: Invalid data for player in line 82 1-6.
 
82 CHAR .Danny 6 6 1
ZONE 04666723232322222222222222222222222222222222222222222222222222222222222222222222
NUMR 941EE906060100000000000000000000000000000000000000000000000000000000000000000000
player=. goals=6 age=6 years_played=1 _ERROR_=1 _N_=5
NOTE: Invalid data for player in line 83 1-4.
 
83 CHAR .Pat 7 5 1
ZONE 05672323232222222222222222222222222222222222222222222222222222222222222222222222
NUMR 90140705010000000000000000000000000000000000000000000000000000000000000000000000
player=. goals=7 age=5 years_played=1 _ERROR_=1 _N_=6
NOTE: Invalid data for player in line 84 1-5.
 
84 CHAR .John 15 9 5
ZONE 04666233232322222222222222222222222222222222222222222222222222222222222222222222
NUMR 9AF8E015090500000000000000000000000000000000000000000000000000000000000000000000
player=. goals=15 age=9 years_played=5 _ERROR_=1 _N_=7
NOTE: Invalid data for player in line 85 1-6.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+
 
85 CHAR .Betty 12 10 3
ZONE 04677723323323222222222222222222222222222222222222222222222222222222222222222222
NUMR 92544901201003000000000000000000000000000000000000000000000000000000000000000000
player=. goals=12 age=10 years_played=3 _ERROR_=1 _N_=8
NOTE: The data set WORK.SOCCER_SCORES has 8 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
 
 
86 ;
87 Run;
88
89 proc print data=soccer_scores;
90 var player age goals;
91 run;
 
NOTE: There were 8 observations read from the data set WORK.SOCCER_SCORES.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds
 
 
92
93
94 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
107
Cynthia_sas
SAS Super FREQ

Hi: When you read data with an INPUT statement, one of the important pieces of information that needs to be determined is HOW to read the variable. By default, with an INPUT statement such as you have, you are telling SAS that ALL your values (after DATALINES) are numeric.

This presents SAS with a problem and the NOTE tells you exactly what the problem is:
"NOTE: Invalid data for player ..." SAS is trying to read "Rachel" from the first row and "Bobby" from the second row as numbers. That means you did not specify the correct method for reading the PLAYER value.

The typical indicator for reading a character value, with SAS, in an INPUT statement is to use a $ (dollar sign). There are a couple of different ways to read your data, but with list input, the easiest way is to read about the INPUT statement and look at some examples and see if you can figure out where a $ would belong in your INPUT statement to read PLAYER.

The default length for a character variable is 8 so if you KNOW that you only have names that are 8 bytes in length (or less) then you are OK with the default; however if you will have names longer than 8, then you might need a LENGTH statement.

Just a quick Google search revealed a nice example here:
http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a003209907.htm

for LIST input that shows you both the use of the $ and the use of the LENGTH statement.

Cynthia

RaginiS
Fluorite | Level 6

Thanks for your response and valuable explanation! That makes sense!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 638 views
  • 0 likes
  • 3 in conversation