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.
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
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;
Is this better?
Log: Program 1
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
Thanks for your response and valuable explanation! That makes sense!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.