BookmarkSubscribeRSS Feed
Ashwini
Calcite | Level 5

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

Thanks,

Regards,

Ashwini

3 REPLIES 3
art297
Opal | Level 21

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

Ashwini
Calcite | Level 5

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

art297
Opal | Level 21

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 1230 views
  • 0 likes
  • 2 in conversation