BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ramya_sahu
Obsidian | Level 7

Hi All,

 

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

 

Thanks in advance..

 

Ramya

1 ACCEPTED SOLUTION

Accepted Solutions
avinashns
Obsidian | Level 7
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

7 REPLIES 7
Kurt_Bremser
Super User

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.

ramya_sahu
Obsidian | Level 7

Thanks for your response

 

avinashns
Obsidian | Level 7
filename orders 'C:\orders.txt';

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

Thanks Avinas.. it worked.

user24feb
Barite | Level 11

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...

ramya_sahu
Obsidian | Level 7

 

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

 

 

 
Kurt_Bremser
Super User

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

 

 


 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 7 replies
  • 1143 views
  • 1 like
  • 4 in conversation