BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
1 REPLY 1
Patrick
Opal | Level 21
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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1278 views
  • 0 likes
  • 2 in conversation