Hello
I want to create a data set with one column with names of files exists in a folder.
I run this code and get error.
NOTE: Argument 1 to function DNUM(0) at line 158 column 13 is invalid.
ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY expression is missing, zero,
or invalid.
fref=#LN00027 fname= did=0 i=1 _ERROR_=1 _N_=1
There is a problem with do statement (dnum(did)).
Instead of dnum(did) I wrote 20 (just for example) and then I recieve a data set with column fname with 20 rows but all of them with null values .
May anyone help please?
data filenames;
length fref $8 fname $200;
did = filename(fref,'\\path\');
/*creates a file reference for the directory */
did = dopen(fref);
/*opens the directory */
/*creates a handle -DOPEN*/
do i = 1 to dnum(did);
fname = dread(did,i);
output;
end;
/*loops over all (DNUM) entries in the directory*/
/*and reads each (DREAD)*/
did = dclose(did);
did = filename(fref);
/*At the end, it deassigns the handle and the file reference*/
keep fname;
run;
@Ronein here you can go just updating the path in macro variable.
%LET PATH=;
%LET PATH=;
DATA filenames;
RC=FILENAME("FILEREF","&PATH.");
MYDIR=DOPEN("FILEREF");
IF MYDIR > 0 THEN
NUM=DNUM(MYDIR);
DO I=1 TO NUM;
IF I > 0 THEN DO
FILERE2=DREAD(MYDIR,i);
OUTPUT;
END;
END;
rc=dclose(mydir);
RUN;
did=0 means that the file cannot be found, or is not a directory.
I suspect that your SAS session does not have access to the same shared network resource that you use from your desktop.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.