Hi there
I entered 30 lines but studio only read 10 with data showed.It didn't show the data for another two numerical columns instead it only showed 10 columns of the first row. the others are dash sybols.
Where must dollar signs ($) be placed, so SAS would read the data set correctly?
Can you help me with it? Thx.
Can you post the code you used?
Show the code you used and log. There are common conditions that will make SAS read lines incorrectly and there may be messages in the log such "went to the next line". Example data will help also.
If you are asking about $ on an Input statement it is after the variable to read as character.
Can you post the code you used - it's not really possible to give you an answer otherwise.
Yes. Thanks.
data exercise1;
input Team $ Attendance Price;
cards;
Atlanta | 13993 | 20.06 |
Boston | 14916 | 22.54 |
Charlotte | 23901 | 17 |
Chicago | 18404 | 21.98 |
Cleveland | 16969 | 19.63 |
Dallas | 16868 | 17.05 |
Denver | 12668 | 17.4 |
Detroit | 21454 | 24.42 |
Golden State | 15025 | 17.04 |
Houston | 15846 | 17.56 |
Indiana | 12885 | 13.77 |
LA Clippers | 11869 | 21.95 |
LA Lakers | 17378 | 29.18 |
Miami | 15008 | 17.6 |
Milwaukee | 16088 | 14.08 |
Minnesota | 26160 | 10.92 |
New Jersey | 12160 | 13.31 |
New York | 17815 | 22.7 |
Orlando | 15606 | 20.47 |
Philadelphia | 14017 | 19.04 |
Phoenix | 14114 | 16.59 |
Portland | 12884 | 22.19 |
Sacramento | 17014 | 16.96 |
San Antonio | 14722 | 16.79 |
Seattle | 12244 | 18.11 |
Utah | 12616 | 18.41 |
Washington | 11565 | 14.55 |
;
proc print data=exercise1;
run;
Can you please repost that using the insert code at the top of the editor.
It's likely an issue with spaces vs tabs, but the browser is going to mess it up if you don't post it as pure text.
You have at least two problems.
First when you use
Input team $ ...
The length of the team will default to 8 characters. So you need more to tell SAS that you need to read at least 12 characters.
Second is that you have spaces in some of the team names.
The input statement you are using is called "list input". By default, unless using file that has a specific delimiter and you tell SAS what the delimiter may be, the space separtes the "words" so Golden would be the first "word" and without additional information SAS reads the "word" as the Attendance. Since "State" is not a number then you get an error, there would be an entry in the log about that, and the value is set to missing.
Depending on exactly what your input actually looks like there are different approaches to read the data.
Very old school is fixed column. In the following example the values after the team names are moved enough columns to have spaces and then tell SAS to rean the team name from the first 12 columns before using list input for the other two variables.
data exercise1; input Team $ 1-12 Attendance Price; cards; Atlanta 13993 20.06 Boston 14916 22.54 Charlotte 23901 17 Chicago 18404 21.98 Cleveland 16969 19.63 Dallas 16868 17.05 Denver 12668 17.4 Detroit 21454 24.42 Golden State 15025 17.04 Houston 15846 17.56 Indiana 12885 13.77 LA Clippers 11869 21.95 LA Lakers 17378 29.18 Miami 15008 17.6 Milwaukee 16088 14.08 Minnesota 26160 10.92 New Jersey 12160 13.31 New York 17815 22.7 Orlando 15606 20.47 Philadelphia 14017 19.04 Phoenix 14114 16.59 Portland 12884 22.19 Sacramento 17014 16.96 San Antonio 14722 16.79 Seattle 12244 18.11 Utah 12616 18.41 Washington 11565 14.55 ; run
Other approaches would be using a delimeter such as a comma between each value tell SAS to use comma as a delimeter.
data exercise1; input Team $ 1-15 Attendance 8. Price 8.; cards; Atlanta 13993 20.06 Boston 14916 22.54 Charlotte 23901 17 Chicago 18404 21.98 Cleveland 16969 19.63 Dallas 16868 17.05 Denver 12668 17.4 Detroit 21454 24.42 Golden State 15025 17.04 Houston 15846 17.56 Indiana 12885 13.77 LA Clippers 11869 21.95 LA Lakers 17378 29.18 Miami 15008 17.6 Milwaukee 16088 14.08 Minnesota 26160 10.92 New Jersey 12160 13.31 New York 17815 22.7 Orlando 15606 20.47 Philadelphia 14017 19.04 Phoenix 14114 16.59 Portland 12884 22.19 Sacramento 17014 16.96 San Antonio 14722 16.79 Seattle 12244 18.11 Utah 12616 18.41 Washington 11565 14.55 ; run; proc print; run;
To post SAS code, use the "little running man" icon on top of the post editor. This will preserve code formatting, and display in a "enhanced-editor-like" coloring. For logs or list data, use the {i} icon; preserves formatting, but does no coloring.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.