Given the following raw data records in DATAFILE.TXT:
----|----10---|----20---|----30
Kim,Basketball,Golf,Tennis
Bill,Football
Tracy,Soccer,Track
The following program is submitted:
data WORK.SPORTS_INFO;
length Fname Sport1-Sport3 $ 10;
infile ‘DATAFILE.TXT’ dlm=’,’;
input Fname $ Sport1 $ Sport2 $ Sport3 $;
run;
proc print data=WORK.SPORTS_INFO;
run;
Which output is correct based on the submitted program?
A.
| Obs | Fname | Sport1 | Sport2 | Sport3 |
| 1 | Kim | Basketball | Golf | Tennis |
| 2 | Bill | Football | ||
| 3 | Tracy | Soccer | Track |
B.
| Obs | Fname | Sport1 | Sport2 | Sport3 |
| 1 | Kim | Basketball | Golf | Tennis |
| 2 | Bill | Football | Football | Football |
| 3 | Tracy | Soccer | Track | Track |
C.
| Obs | Fname | Sport1 | Sport2 | Sport3 |
| 1 | Kim | Basketball | Golf | Tennis |
| 2 | Bill | Football | Tracy | Soccer |
D.
| Obs | Fname | Sport1 | Sport2 | Sport3 |
| 1 | Kim | Basketball | Golf | Tennis |
| 2 | Bill | Football |
Why is the c and not a?
Thanks
The INPUT statement reads line by line. when the first line is finished reading then it goes to second line to look for data untill the INPUT statement finish reading all variable values. If the line has a missng values you have to use MISSOVER in the INFILE.
The belove code gives option A
data WORK.SPORTS_INFO;
length Fname Sport1-Sport3 $ 10;
infile 'datafile.txt' dlm=',' missover;
input Fname $ Sport1 $ Sport2 $ Sport3 $;
run;
proc print data=WORK.SPORTS_INFO;
run;
The INPUT statement reads line by line. when the first line is finished reading then it goes to second line to look for data untill the INPUT statement finish reading all variable values. If the line has a missng values you have to use MISSOVER in the INFILE.
The belove code gives option A
data WORK.SPORTS_INFO;
length Fname Sport1-Sport3 $ 10;
infile 'datafile.txt' dlm=',' missover;
input Fname $ Sport1 $ Sport2 $ Sport3 $;
run;
proc print data=WORK.SPORTS_INFO;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.