Help using Base SAS procedures

IMPORTing to all Character

Reply
Valued Guide
Posts: 634

IMPORTing to all Character

I would like to use PROC IMPORT and force all variables to character.  Since I am reading CSV files, I cannot use the MIXED= option.The attributes of the files are unknown and I am hoping that I will not have to build something to parse them individually.

Super User
Super User
Posts: 7,039

Re: IMPORTing to all Character

I have never seen such an option.

How hard do you want to work to import the file(s)?  Are you willing to accept that all variables are the same length?  If so then read the first line into a macro variable that you can use as the list of variable names.

data _null_;

  infile tmpfile1 obs=1 ;

  input ;

  call symputx('varlist',translate(_infile_,' ',','));

run;

data want ;

  infile tmpfile1 dsd firstobs=2 truncover ;

  length &varlist $200 ;

  input &varlist ;

run;

Super User
Posts: 10,020

Re: IMPORTing to all Character

Doc Arthuer,

I am afraid that is hard for proc import . As Tom mentioned There is not an option to control it. The only thing I can think is about modify that csv file and import it.

data _null_;
 infile  'c:\temp\x.csv' ;
 file 'c:\temp\temp.csv';
 input;
 _infile_=tranwrd(cats(_infile_,'09'x),',',cats('09'x,','));
 put _infile_;
run;


proc import datafile='c:\temp\temp.csv' out=x dbms=csv replace;run;

Ksharp

Message was edited by: xia keshan

Valued Guide
Posts: 634

Re: IMPORTing to all Character

That was what I thought, but was hoping that I had missed something.  Brute force it will be.

Thanks

Respected Advisor
Posts: 3,799

Re: IMPORTing to all Character

Not exactly main stream.  Might be a good TRANSPOSE example;

filename FT15F001 temp;
proc import datafile=FT15F001 out=test dbms=csv;
   getnames=no;
   parmcards;
name,name2,name3
1,2,3
1,2,3
41455,2,3
1,2,3
1,2,3
;;;;
   run;
proc transpose out=flip(rename=(col1=name) drop=_name_);
   var _all_;
   run;
proc transpose out=flop;
   id name;
   var col:;
   run;
Super User
Posts: 10,020

Re: IMPORTing to all Character

Posted in reply to data_null__

NULL,

Good to know something new, but that is unfit to large csv file ( 1 G )  or have lots of variables . that will reduce performance very much.

Ksharp

Respected Advisor
Posts: 3,799

Re: IMPORTing to all Character

You’re ability to grasp the obvious is astonishing.:smileyplain:

Valued Guide
Posts: 634

Re: IMPORTing to all Character

Posted in reply to data_null__

Thanks Data _NULL_.  I wish that I could give you a "correct answer" for your 'sincere' praise Smiley Wink 

Super User
Posts: 10,020

Re: IMPORTing to all Character

Posted in reply to data_null__

NULL,

Don't be offended ! Yours is good if csv file is small .

Regards

Xia Keshan

from China

Ask a Question
Discussion stats
  • 8 replies
  • 397 views
  • 7 likes
  • 4 in conversation