-1

I have multiple raw files without header . I want to automate the process in order to create multiples datasets and also once the dataset created need to automate the process when we use logic say **Actvity_flag ='Y'** , I need those datasets to be created which has data in it. No need of datasets with Null Rows.

Below is the Sample Text file

A_Sample.txt
B_Sample.txt
C_Sample.txt
D_Sample.txt

Path: C:\Data\datasets*****.txt

Below are the Variables

Id             1-16
First_Name    17-27 
Last-named    28-47
Phone_no      48-58
Activity_Flag 59-59

Data in text file look like as below

10001   George  Michael 123456789   Y
10002   Henry   Jha     987456123   Y
10003   Rob     Camer   258963147   N
10004   Allan   Cruze   369852147   Y
10005   Andy    wilson  147258369   N
Tom
  • 47,574
  • 2
  • 16
  • 29
  • Why do you need separate datasets? Why not just put them all in one dataset? If you make multiple datasets does it really matter if you create an empty dataset when the text file is empty? – Tom May 11 '21 at 02:35
  • What is `Id`? You did not list any column range for that variable. – Tom May 11 '21 at 02:36
  • 1. Each file is different data with Same variables. There is no scope of File is Empty. Once we create individual datasets. 2. Need to put logic for active records. (Activity=Y) . Some file have active/inactive records with Y Or N Flag. I need those datasets which has Y flag – Andy birada May 11 '21 at 03:32

1 Answers1

0

Read all of the files into one dataset. Keep track of which file the observation was read from. If you want to filter the observations you could add a subsetting IF statement.

data all ;
  length filen $256;
  infile "C:\Data\*.txt" truncover filename=filen;
  input
    Id            $  1-16
    First_Name    $ 17-27 
    Last_Name     $ 28-47
    Phone_No      $ 48-58
    Activity_Flag $ 59-59
  ;
  filename = filen;
  if Activity_Flag = 'Y';
run;

Now if you want to write out multiple datasets you can, but why?

Tom
  • 47,574
  • 2
  • 16
  • 29