BookmarkSubscribeRSS Feed
jdmarino
Fluorite | Level 6

I have a CSV file with 95 columns and I need about 20 of them.  The way I handled this is to have 65 dummy vars (dummy0-dummy64) that are strings, 20 fields (the ones I care about) that are named/informatted and a giant INPUT statement that uses them to read the rows. The last thing I do in my data step is drop dummy0-dummy64.

Is there a better way to do this?  My input statement is kind of ugly.

2 REPLIES 2
data_null__
Jade | Level 19

You don't need but one dummy variable you can use something link INPUT a b c 64*(d) e f g; where d is a one byte character to skip the fields.

I have a program that does something similar in that it reads specific fields from CSVs.  You define a data set with the variables your want to read properly typed and with INFORMATs attached then you call the program and it read the fields that match the variable names from the each CSV.  It will read also from concatenated or wildcard FILEREF.  The fields can be in any order the program just looks for the names.

It's an interesting application of HASH and ARRAY. 

jdmarino
Fluorite | Level 6

That macro is really nifty; I'll give it a try next time.  One of my colleagues solved the same problem using awk. He ends up with single, rational, delimited file which he can then import simple.  Neither he nor I have your SAS skills.

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!

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
  • 6624 views
  • 7 likes
  • 2 in conversation