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

%macro countext (fileref=, dat=);

data file_ex;
keep filename;
length fref $8 filename $80;
rc = filename(fref, %nrstr("'&filref.'"));
if rc = 0 then
do;
did = dopen(fref);
rc = filename(fref);
end;


else do;
length msg $200.;
msg = sysmsg();
put msg=;
did = .;
end;


if did <=0 then putlog 'ERR' 'OR: Unable to open directory.';

dnum=dnum(did);

 

do i=1 to dnum;

filename=dread(did, i);

/* If this entry is a file, then output. */

fid=mopen(did, filename);

if fid>0 then output;

end;

rc=dclose(did);

run;

 

proc sql noprint;

create table file_ex1 as select *, scan(filename, 2, '. ') as ext from file_ex order by ext;

quit;

 

proc freq data=file_ex1 noprint;

tables ext/out=&dat.(drop=percent);

run;

%mend countext;

 

%countext (fileref=/home/abc/Test/new, dat=count_new);

 

 

This macro is used to find the count of files using file extension. I want resolve fileref path to files dataset.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Repeating:

Please run this command

options mprint;

and run your program again

 

SHOW US the LOG from running this macro (all of the LOG from this macro, 100%, every single character, do not chop parts out)

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

And what happens when you run this code? What is the problem that needs to be fixed?

 

Please run this command

options mprint;

and run your program again and SHOW US the LOG from running this macro (all of the LOG from this macro, 100%, every single character, do not chop parts out)

--
Paige Miller
rajeshV89
Fluorite | Level 6

It is showing below message in log.

 

ERROR: Unable to open directory.
NOTE: Argument 1 to function DNUM(0) at line 40 column 40 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=  FILENAME=  RC=0 DID=0 MSG=  DNUM=. I=1 FID=. _ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following places. The
      results of the operations have been set to missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 40:40
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.FILE_EX may be incomplete.  When this step was stopped
         there were 0 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.06 seconds
      cpu time            0.01 seconds

PaigeMiller
Diamond | Level 26

Repeating:

Please run this command

options mprint;

and run your program again

 

SHOW US the LOG from running this macro (all of the LOG from this macro, 100%, every single character, do not chop parts out)

--
Paige Miller

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
  • 1209 views
  • 0 likes
  • 2 in conversation