BookmarkSubscribeRSS Feed
abcd123
Fluorite | Level 6

Hello, All

I have a csv file "abc.csv", it has 5000 variables (var1-var5000, column1 through column5000), and nearly million rows. However I am only interested in var1, var1390,var3782, and var4703. I know I can do it using following code:

filename myfile "abc.csv";

data want(keep=var1 var1390 var3782 var4703);

infile myfile;

input var1-var5000;

run;

However the code do waste  time inputing those un-wanted columns.

My question is: is there a way to input only wanted columns, i.e. var1, var1390,var3782, and var4703?

4 REPLIES 4
Tom
Super User Tom
Super User

It is probably not worth the effort.  Most of the time will be spent waiting for the disk to move the file into memory.  The process of reading in the text version of 5000 variables would be small next to that.

ballardw
Super User

IF the file were fixed column then it would be worth determining the columns and reading just those but CSV is going to yield no joy.

Though I would only input variables Var1-var4703;

I suspect you'll need a large value for lrecl as well.

Tom
Super User Tom
Super User

If you think it is worth the effort then look into some the unix based tools for subsetting CSV files.

http://stackoverflow.com/questions/7857090/awk-extract-specific-columns-from-delimited-file

You could wrap your solution inside of a PIPE and read it in SAS.

filename myfile pipe 'csvfilter -f 1,1390,3782,4703 abc.csv' ;

data want ;

  infile myfile dsd truncover firstobs=2;

  input var1 var1390 var3782 var4703;

run;

abcd123
Fluorite | Level 6

Thanks, Tom. This is very helpful.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 2451 views
  • 4 likes
  • 3 in conversation