Wednesday, October 30, 2013

Read Raw Data File

How to read / access .dat file?

filename statement can be used to create fileref and specify full path of raw data file. Further, infile statement can be used like set statement in data step to access raw data. Finally, input statement is used to define data structure of data set naming how many variables, their names, data type (alpha or numeric) and column numbers. 


It is important that fileref used in filename is same as that used in infile.

Scenario: Enroll raw data file contains information on students ID, Name and CourseID which can be of two types: 1000 denotes Associate degree, 2000 denotes Bachelor degree.

Sample Code:

filename enroll 'C:\sas\enroll.dat';
data work.enrollinfo;
  infile enroll;
  input ID $ 1-4 Name $ 6-25 CourseID $ 27-30;
  
  if CourseID='1000';
     Degree='Associate';
  else if CourseID='2000';
     Degree='Bachelor';  
run;

Constraints on Variable names:
  1. must be 1 to 32 characters in length
  2. must begin with letter (A-Z) or an underscore (_)
  3. can continue with any combination of numerals, letters or underscores




No comments:

Post a Comment