Learning SAS? Welcome to the exclusive online community for all SAS learners.

import txt file

Reply
Contributor
Posts: 61

import txt file

Hello, i would like to know how can i import text file, when the text file includes two files(first column : 01 or 02), for example :

01 120.1 100

02 12/02/2013 30/02/2013

01 130    10

02 10/10/2012 30/10/2015

02 18/01/2010 30/01/2010

for every (01 or 02) we have different variables. How can i import this kind of text file? the aim to create two different files 01 and 02.

thank you

Super User
Posts: 7,771

Re: import txt file

You can do it in one data step;

data

  file1 (keep=var1 number1 number2)

  file2 (keep=var1 date1 date2)

;

infile "whatever";

input var1 @; * This holds the line;

if var1 = 1 then do;

  input number1 number2;

  output file1;

end;

else do;

  input date1 date2;

  output file2;

end;

run;

You must of course provide proper informats for the given variables, depending on the layout.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 61

Re: import txt file

Posted in reply to KurtBremser

that was i did, but doesn't work

Contributor
Posts: 61

Re: import txt file

Posted in reply to KurtBremser

Hi, thank you. you are right. i forget @!

Super User
Posts: 7,771

Re: import txt file

Smiley Wink

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 4 replies
  • 311 views
  • 0 likes
  • 2 in conversation