BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Saket_90
Calcite | Level 5

Hi,

 

I am trying to load the data from multiple text files palced in a folder having the same structure to one file. All the text files are having the same headers.

Sample data in one of the file:

Product                       Customer    Qtr 1     Qtr 2         Qtr 3         Qtr 4
Alice_Mutton               ANTON     28080     70200      110400      55125
Aniseed_Syrup            BERGS     31200     78000      60000       14700
Boston_Crab               BOLID       28080     6000        77280      117000
Escargots_Bourgogne BOTTM    117000    20000     16560       122360
Filo_Mix                       ERNSH     112320   18000      92000       260715
Geitost                         GODOS    6240       28080      24840       41952

 

Also the names of the file are cust101, cust102, cust103.........Cust200...

 

Can anyone please suggest an efficient way to read the data from all these text file in to a single file.

 

Regards,

Saket

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Here's my recommended solution:

 

https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-tex...

 

1. You need your input/informat/format statement for reading a single file.

2. In the code in link above, change the path, and use a wildcard to reference the data.

3. Make sure to use the EOV= variable to avoid reading the header in each file.

 

View solution in original post

3 REPLIES 3
Pamela_JSRCC
Quartz | Level 8

You can read multiple files using wildcrds. The code below is not tested but should help get you started.

 

%let data_filepath = c:\...\cust*;  * modify path as appropriate for your system;

 

data temp;
infile firstobs=2 "&data_filepath";
input product $ customer $ qtr1-qtr4;
run;

Reeza
Super User

Here's my recommended solution:

 

https://communities.sas.com/t5/SAS-Communities-Library/How-do-I-write-a-macro-to-import-multiple-tex...

 

1. You need your input/informat/format statement for reading a single file.

2. In the code in link above, change the path, and use a wildcard to reference the data.

3. Make sure to use the EOV= variable to avoid reading the header in each file.

 

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