BookmarkSubscribeRSS Feed
cd2011
Calcite | Level 5

Hi,

 

I have a challenge importing CSV files.

 

1) my csv file has over 100 columns, but I only need <20. So I have been doing proc import and then "keep" statement. Is there a way to import only few columns out of these 100+ using other procedures, maybe INFILE ?

 

2) The other issue I am haivng is that some of these 100+ variable names are very long, so when I import them the names get truncated. How do I avoid that ? I am considering INFILE and do the INFORMAT statement with INPUT But then I dont want to write the name of 100+ variables with INPUT option whereas I only need 10-20 at the most.

 

Thanks a bunch in advance.

 

-CD

3 REPLIES 3
LinusH
Tourmaline | Level 20
1) Well yes, the data step where you explicitly define the variablesame to import. From a strictly syntax point of view, I would consider proc import with keep= easier to write than a data step with selection of variables.

2) SAS variable names can only be max 32 chars. You cannot avoid that with input or any other technique.
Data never sleeps
ballardw
Super User

One set of possible solutions for both questions is the same:

Proc import generated datastep code to read csv files. After you run proc import there will be code in the log for that data step.

 

Copy the code from the log into the editor. Remove any variables from INFORMAT, FORMAT and INPUT statements past the last one you want. If some other variables are still there, add a DROP statement for those.

 

To get useable, nicer names, do a search and replace on the generated names to what you would like.

 

I recommend adding a label statement to describe the columns you want.

 

Unfortunately the way delimited data read with list input you can't skip any variables. But you need not read the entire row, just up to the last one you want.

cd2011
Calcite | Level 5

Thank you. I will try this.

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
  • 3 replies
  • 933 views
  • 0 likes
  • 3 in conversation