Hi All.
I want to create a dataset by parsing a fix length file and where each dataline contains the value for specific variables and not for all always.
e.g.
The target dataset column structure is:
Row# Type Name1 Name2 Name3 Amount1 Amount2 Amount3
The corresponding datalines in the file appears as:
A,John,1000
B,Mac,1200
C,Amar,1100
B,Jack,1300
B,Maria,1200
A,Meg,1400
C,Rohan,100
.
.
.
Rules:
* Each line contains one record for a dataset.
* Each line contains the data for only one Name variable and one Amount variable at the fix position.
* Based on the value of first variable(Type), the next values should get assigned to the corresponding variables as follow -
Type A --> Name1, Amout1 (rest all the variables in the dataset will be null)
Type B --> Name2, Amout2 (rest all the variables in the dataset will be null)
Type C --> Name3, Amout3 (rest all the variables in the dataset will be null)
* The datalines are shuffled and not in sequence of A,B,c compulsarily.
* The no. of dataliens are in millions.
The final dataset must look like -
Dataset:
Row# Type Name1 Name2 Name3 Amount1 Amount2 Amount3
1 A John 1000
2 B Mac 1200
3 C Amar 1100
4 B Jack 1300
5 B Maria 1200
6 A Meg 1400
7 C Rohan 1000
.
.
.
Solution:
In order to achieve above requirement, I have used the trailing "@" feature in the following code which is working quite ok.
Data .myDataset;
Infile ;
Input Type $1 @;
If Type = "A" then
Input Name1 $ Amount1;
If Type = "B" then
Input Name2 $ Amount2;
If Type = "C" then
Input Name3 $ Amount3;
run;
Query:
Just want to confirm it it is the only option to deal with such scenario. Considering the processing of million records, is there any other better alternative to achieve the above task.
Any help regarding this will be highly appreciated.
regards
Kapil Agrawal