DATA Step, Macro, Functions and more

how to extract 3 file at a time

Reply
Frequent Contributor
Posts: 76

how to extract 3 file at a time

How to extract 3 file at time,one is in .txt format and other is in .csv format ?

Thanks,

Regards,

Ashwini

PROC Star
Posts: 7,468

how to extract 3 file at a time

You have to provide more info like: extract from what? to what 3rd format (you only listed 2)?

Frequent Contributor
Posts: 76

Re: how to extract 3 file at a time

Daer Art,

I have 3 file 1st one is in text file in .txt format and other two file are in CSV file in .csv format.

I want to merge the data in three file and make a one dataset.

1.How i take this file in sas environment using a single code?

2.How i merge these file?

3.How I send this output in raw data?

Thanks,

Regards,

Ashwini

PROC Star
Posts: 7,468

Re: how to extract 3 file at a time

Depends upon how similar the files are and exactly how you have to import them.  Yes, it MAY be doable in one datastep.  Below, I create two csv files, one space delimited file and one tab delimited file, and then import all 4 in one datastep.  However, without knowing what SAS skills you have, or what your files actually look like, this may be an extreme oversimplification:

/*create test data*/

data _null_;

  input x y z;

  file "c:\art\test\csv1.csv";

  put x "," y "," z;

  cards;

1 2 3

4 5 6

;

data _null_;

  input x y z;

  file "c:\art\test\csv2.csv";

  put x "," y "," z;

  cards;

7 8 9

10 11 12

;

data _null_;

  input x y z;

  file "c:\art\test\txt1.txt";

  put x y z;

  cards;

13 14 15

16 17 18

;

data _null_;

  input x y z;

  file "c:\art\test\txt2.txt";

  put x "09"x y "09"x z;

  cards;

19 20 21

22 23 24

;

/*get file names*/

filename indata pipe "dir c:\art\test\*.* /b";

/*import all 4 files in 1 datastep*/

data want;

  length fil2read $100;

  informat fn $50.;

  infile indata truncover;

  input fn &;

  fil2read="c:\art\test\"||fn;

  if scan(fil2read,-1) eq "csv" then delim=",";

  else delim=" ";

  done=0;

  infile dummy filevar=fil2read dlm=delim end=done;

  do while(not done);

    input Var1-var3;

  end;

run;

Ask a Question
Discussion stats
  • 3 replies
  • 139 views
  • 0 likes
  • 2 in conversation