Hi All,
I am very much new to SAS. So, Please help me importing attached text file to SAS.
Thanks in advance..
Ramya
filename orders 'C:\orders.txt';
data want;
infile orders firstobs=2;
informat orderdate date7.;
format orderdate date7.;
input ID Orderdate Model $12. Quantity;
run;
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.
Thanks for your response
filename orders 'C:\orders.txt';
data want;
infile orders firstobs=2;
informat orderdate date7.;
format orderdate date7.;
input ID Orderdate Model $12. Quantity;
run;
Thanks Avinas.. it worked.
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;
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
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
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!
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.