Help using Base SAS procedures

Parsing the Unformatted Raw data file to create a SAS Dataset

Reply
N/A
Posts: 0

Parsing the Unformatted Raw data file to create a SAS Dataset

I have to read a raw data file which has multiple rows. Each row has different data and identified by first 5 characters. Each row has to be parsed and stored to SAS Dataset.

For eample one row is as below:

03ABW123456789Firstname MA lastname JR 111111111125 Y23456789019850121emailid@email.com

The first 5 characters are the segment Identifier is "03ABW".
Next 9 digits are SSN.
Next 35 chars are First Name
Next 35 chars are Middle Name
Next 35 chars are Last Name
Next 4 chars are Generation
And so on..

For creating the data set with the following fileds
SSN $9
First Name $35
Middle Name $35
Last Name $35
...

I am using the following

DATA NAME
INFILE '/home/xxx/NAME.txt';

INPUT @'03ABW' Applicant_SSN $9
+1 APP_FIRST_NAME $35 ;

I am using the segment ID '03ABW' to go the correct row.
1) How do I go to different rows in the raw data file ?
2) How do I to the adjacent columns in a row to get the SSN/Names etc.
3) How do I move by a specified displacement and get that data from INPUT statement to populate in the dataset fields? Message was edited by: MR
Respected Advisor
Posts: 4,173

Re: Parsing the Unformatted Raw data file to create a SAS Dataset

Posted in reply to deleted_user
Hi

Sounds like a hierarchical data structure (mainframe?).

The following code example assumes that there are always 2 records of raw data which make up a SAS observation.

This is most likely not how your raw dataset structure looks like but it should give you the idea. The most important thing is the '@' used in the input statement (there is also an '@@' - look it up in the doc).

data demo;
infile datalines truncover;
retain var1 var2;
input Segment $ 1-2 ID $ 3-5 @;
if segment='01' then
do;
input var1 6-12;
end;
else
if segment='02' then
do;
input var2 6-12;
output;
end;
datalines;
01ABW12
02ABW13
01AEW234
02AEW245
;
run;

proc print data=demo;
run;

HTH
Patrick
Ask a Question
Discussion stats
  • 1 reply
  • 194 views
  • 0 likes
  • 2 in conversation