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


Hello,

 

I have multiple text files in zipped format in a folder. I want to get all filenames in one SAS dataset. 

 

For example:

H:\SAS\Project\ABC_20190811.txt.gz

H:\SAS\Project\PQR_20190811.txt.gz

H:\SAS\Project\XYZ_20190811.txt.gz

H:\SAS\Project\JKL_20190811.txt.gz

 

Output:

ABC_20190811

PQR_20190811

XYZ_20190811

JKL_20190811

 

Thanks,

Kinjal

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Read the names. Then parse the names to extract the part you want.

data filenames ;
  infile 'dir H:\SAS\Project\*.txt.gz /b' pipe truncover;
  input filename $256. ;
  membername = scan(scan(filename,-1,'\'),1,'.');
run;

View solution in original post

3 REPLIES 3
Shmuel
Garnet | Level 18

1) Do you know to import one zipped file ?

2) Read the article in this link: https://support.sas.com/resources/papers/proceedings/proceedings/sugi31/155-31.pdf

3) Read each file and append it to a desired sas dataset name.

 

Post your code and log in case of issues using the {i} icon above. 

Tom
Super User Tom
Super User

Read the names. Then parse the names to extract the part you want.

data filenames ;
  infile 'dir H:\SAS\Project\*.txt.gz /b' pipe truncover;
  input filename $256. ;
  membername = scan(scan(filename,-1,'\'),1,'.');
run;
KinjalPatel
Fluorite | Level 6

Thank you Tom! You are genius!

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 621 views
  • 1 like
  • 3 in conversation