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

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.

ObsFnameSport1Sport2Sport3
1KimBasketballGolfTennis
2BillFootball  
3TracySoccerTrack 

B.

ObsFnameSport1Sport2Sport3
1KimBasketballGolfTennis
2BillFootball Football Football
3TracySoccerTrack Track

C.

ObsFnameSport1Sport2Sport3
1KimBasketballGolfTennis
2BillFootballTracySoccer

D.

 

ObsFnameSport1Sport2Sport3
1KimBasketballGolfTennis
2BillFootball


Why is the c and not a?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

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;

Thanks,
Suryakiran

View solution in original post

2 REPLIES 2
SuryaKiran
Meteorite | Level 14

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;

Thanks,
Suryakiran

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 1611 views
  • 1 like
  • 2 in conversation