0
votes

The problem said: The first line is a header line and should not be read (use the infile option firstobs=2) The remaining lines contain and ID number(character). gender(character), date of birth DOB, and two scores 1 and 2. Note that there are some missing values for the scores, and you want to be sure that SAS does not go to a new line to read these values. Write a SAS DATA STEP TO READ DOB with DATE9. Here are the lines of data(I put it in my code to save space).

DATA READ;                                                                                                                              
INFILE DATALINES FIRSTOBS=2;                                                                                                           
 INPUT   ID  1-3                                                                                                                        
     GENDER $  5                                                                                                                    
  @7   DOB  mmddyy10.                                                                                                               
  @   SCORE1  3                                                                                                                     
  @   SCORE2  3                                                                                                                     
;                 



DATALINES;                                                                                                                              
***Header line: ID GENDER DOB SCORE1 SCORE2                                                                                             
001 M 10/10/1976 1OO 99                                                                                                                 
002 F 01/01/1960 89                                                                                                                     
003 M 05/07/2001 90 98                                                                                                                  
;                                                                                                                                       

DATA PROB12_8;                                                                                                                          
SET READ;                                                                                                                               
FORMAT DOB MMDDYY9.;                                                                                                                    
RUN;                                                                                                                                    


PROC PRINT DATA=PROB12_8;                                                                                                               
RUN;                                                                                                                                    

My output is:

OBS ID GENDER DOB SCORE1 SCORE2
1    1    M     .    .       99      
2    2    F     .    89      .
3    3    M     .    90      98

I don't understard why the program read in that way, if I specify the amount of spaces and use the pointer in my program.

Thanks for your help.

1

1 Answers

0
votes

Your problems start at SCORE1 and SCORE2 you have the pointer control specified incorrectly. Also notice that 1OO is not 100. This file can be read easily with list input and missover infile statement option.

DATA READ;                                                                                                                              
   INFILE DATALINES FIRSTOBS=2 missover;
   informat id $3. gender $1. dob mmddyy10.;
   input ID GENDER DOB SCORE1 SCORE2;
   format dob mmddyy10.;
   datalines; 
***Header line: ID GENDER DOB SCORE1 SCORE2                                                                                             
001 M 10/10/1976 1OO 99                                                                                                                 
002 F 01/01/1960 89                                                                                                                     
003 M 05/07/2001 90 98                                                                                                                  
;;;;                   
   run;

enter image description here