BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Onyx | Level 15

Hello

I am doing export of SASHELP.CARS data set into txt file.

Then I want to import it using infile statement and also I want to control the columns names .

However, as you can see in the result of import there is a problem.

The original columns names are in the data set ..

what  is the way to solve it please?


/***export to txt file with column headers*/
proc export data=sashelp.cars
outfile="/path/cars.txt" 
dbms=tab
replace;
run;

/*Import*/
data cars; 
infile  "/path/cars.txt"  dlm='09'X dsd truncover;
input Carmake :$50.
      Carmodel  :$50.
	  Cartype :$50.
	  origin  :$50.
	  DriveTrain :$50.
	  MSRP 
	  InvoiceNumber 
	  EngineSize 
	  NumberCylinders
	  HP
	  MPG_In_City
	  MPG_In_Highway
	  CarWeight
	  Wheelbase	;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Ronein
Onyx | Level 15

Okay, I found the solution.

Need to use firstobs=2 

data cars; 
infile "/path/carstbl1.txt" 
		 firstobs=2
        dlm='09'X dsd truncover;
input Carmake :$50.
      Carmodel  :$50.
	  Cartype :$50.
	  origin  :$50.
	  DriveTrain :$50.
	  MSRP : $8.
	  InvoiceNumber  : $8.
	  EngineSize 
	  NumberCylinders
	  HP
	  MPG_In_City
	  MPG_In_Highway
	  CarWeight
	  Wheelbase	;
run;

View solution in original post

2 REPLIES 2
Ronein
Onyx | Level 15

Okay, I found the solution.

Need to use firstobs=2 

data cars; 
infile "/path/carstbl1.txt" 
		 firstobs=2
        dlm='09'X dsd truncover;
input Carmake :$50.
      Carmodel  :$50.
	  Cartype :$50.
	  origin  :$50.
	  DriveTrain :$50.
	  MSRP : $8.
	  InvoiceNumber  : $8.
	  EngineSize 
	  NumberCylinders
	  HP
	  MPG_In_City
	  MPG_In_Highway
	  CarWeight
	  Wheelbase	;
run;
scottyniven
Calcite | Level 5

Hey, man

I am having troubles with my dataset. I'm getting a invalid option name INPUT. Help would be appreciated...

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1045 views
  • 0 likes
  • 2 in conversation