BookmarkSubscribeRSS Feed
ArtC
Rhodochrosite | Level 12

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.

8 REPLIES 8
Tom
Super User Tom
Super User

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;

Ksharp
Super User

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

ArtC
Rhodochrosite | Level 12

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

Thanks

data_null__
Jade | Level 19

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;
Ksharp
Super User

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

data_null__
Jade | Level 19

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

ArtC
Rhodochrosite | Level 12

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

Ksharp
Super User

NULL,

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

Regards

Xia Keshan

from China

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 8 replies
  • 1174 views
  • 7 likes
  • 4 in conversation