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

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
Meteorite | Level 14

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
Meteorite | Level 14

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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 726 views
  • 0 likes
  • 2 in conversation