BookmarkSubscribeRSS Feed
stf5018
SAS Employee

I am trying to get the names of all files (including file extension) that are contained in an Azure Data Lake and put them in a table using a loop that goes through the directory. My code can successfully get all the files, starting at a user-supplied base directory, and store their names using the "dread" but it cuts off the last character. How do I get the full name (including extension) without the last character missing? I don't understand why the last character is cut off. I have tried different files, file types, folders, and all combinations thereof. 

 

Code is below along with screenshots of what's contained in ADLS and the "files" table I am storing the output of the code in. Notice that the table has "ds_0" instead of "ds_01" and "process.cs" instead of "process.csv".

 

Images: (Left) Azure Data Lake Container, (Right) SAS table with filenames

7f218312-a3d2-4034-abde-574087c85fc2.png

b065b66e-996a-440b-8aef-5d0c34abd228.png

 

 

options azuretenantid = "###-###-###-";

%let appId="###-###-###-";
%let acctName="###";
%let filesys="###";

filename d adls "/"
   applicationId=&appId 
   accountname=&acctName 
   filesystem=&filesys;

data files;

	folder_id = dopen("d");
	put folder_id=;

	num_files = dnum(folder_id);
	put num_files=;

	do i = 1 to num_files;
		length name $256 ;
		name=dread(folder_id,i);
		output;
	end;

	closerc = dclose(folder_id);
	put closerc=;
run;

 

2 REPLIES 2

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1054 views
  • 0 likes
  • 2 in conversation