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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 882 views
  • 0 likes
  • 2 in conversation