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
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;
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.
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;
Thank you Tom! You are genius!
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.