DATA Step, Macro, Functions and more

SAS import text file

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

SAS import text file

[ Edited ]

Hi All,

 

I am very much new to SAS. So, Please help me importing attached text file to SAS.

 

Thanks in advance..

 

Ramya


Accepted Solutions
Solution
‎02-28-2017 03:13 AM
Occasional Contributor
Posts: 8

Re: SAS import text file

Posted in reply to ramya_sahu
filename orders 'C:\orders.txt';

data want;
	infile orders firstobs=2;
	informat orderdate date7.;
	format orderdate date7.;
	input ID Orderdate Model $12. Quantity;
run;

View solution in original post


All Replies
Super User
Posts: 7,758

Re: SAS import text file

[ Edited ]
Posted in reply to ramya_sahu

Since you have fixed columns, the blanks in the model text don't matter.

Use formatted input with position modifiers:

input
  @1 id 3.
  @5 orderdate date9.

and so on. Use the truncover option in the infile statement, since your last column has a variable number of digits.

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

Re: SAS import text file

Posted in reply to KurtBremser

Thanks for your response

 

Solution
‎02-28-2017 03:13 AM
Occasional Contributor
Posts: 8

Re: SAS import text file

Posted in reply to ramya_sahu
filename orders 'C:\orders.txt';

data want;
	infile orders firstobs=2;
	informat orderdate date7.;
	format orderdate date7.;
	input ID Orderdate Model $12. Quantity;
run;
Contributor
Posts: 23

Re: SAS import text file

Posted in reply to avinashns

Thanks Avinas.. it worked.

Super Contributor
Posts: 340

Re: SAS import text file

Posted in reply to ramya_sahu

Your file does not open. Proc import might be easier.

 

proc import datafile=.. your path ../order.txt''
            out=order
            dbms=dlm
            replace;
     delimiter='09'x; * for tab-delimited files;
run;

 

 

http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#n1w1xy48wd290bn1mqali...

Contributor
Posts: 23

Re: SAS import text file

Posted in reply to user24feb

 

Thanks. for below file format is it possible?

 

ID Orderdate Model Quantity
287 15OCT03 Delta Breeze 15
287 15OCT03 Santa Ana 15
274 16OCT03 Jet Stream 1
174 17OCT03 Santa Ana 20
174 17OCT03 Nor'easter 5
174 17OCT03 Scirocco 1
347 18OCT03 Mistral 1
287 21OCT03 Delta Breeze 30
287 21OCT03 Santa Ana 25

 

 

 
Super User
Posts: 7,758

Re: SAS import text file

Posted in reply to ramya_sahu

To deal with blanks in values, you either need fixed columns, or enclose the fields containing blanks in quotes, or use a field separator other than a blank (eg .csv file with commas as separator).

Everything else needs lots of programming effort to determine which "words" belong into one column.


ramya_sahu wrote:

 

Thanks. for below file format is it possible?

 

ID Orderdate Model Quantity
287 15OCT03 Delta Breeze 15
287 15OCT03 Santa Ana 15
274 16OCT03 Jet Stream 1
174 17OCT03 Santa Ana 20
174 17OCT03 Nor'easter 5
174 17OCT03 Scirocco 1
347 18OCT03 Mistral 1
287 21OCT03 Delta Breeze 30
287 21OCT03 Santa Ana 25

 

 


 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 223 views
  • 1 like
  • 4 in conversation