BookmarkSubscribeRSS Feed
samchat
Calcite | Level 5

Hi All,

I came across a macro, and I believe I got the basic understanding of the program, but would like some confirmation.

datalogread;

length file $256 dye 8 dte1 8 directory $256;

format dte datetime;

keep file dye dte1 directory;

length filrf filerfb $8;

directory =‘&directory’;

rc1=filename(filrf,directory);

opdir=dopen(filrf);

memcount=dnum(opdir);

if opdir <=0 then put ‘ERROR: Unable to open log folder.’;

do i=1 to memcount;

file=dread(opdir,i);

rc2=filename(filrfb,catx(‘\’,directory,file));

fid=fopen(filrfb);

dte=input (finfo(fid,’Create Time’),datetime.);

dte1=dte;

if dye >=&lastrun then output;

rc3=fclose(fid)

rc4=filename(filrfb);

end;

rc5=dclose(opdir);

run;

Would appreciate another pair of eyes, to help me understand this program.

Your help on this is greatly appreciated.

Thanks You.

4 REPLIES 4
Reeza
Super User

What do you think it does? And what don't you understand?

Best way to understand code when learning is to comment every line.

samchat
Calcite | Level 5

It looks like the program is indicating to go to a specified directory, check the files (possibly log files) and check the files for errors.

Cynthia_sas
SAS Super FREQ

Hi, ... to add onto the previous comments...

  And, the only possible reference to anything to do with SAS macro processing is this statement:

directory ='&directory';

which may or may not be a reference to a SAS macro variable. Do you know whether &directory is a SAS macro variable? And if so, does this program even work? Can you find a statement where the value of &directory is set (such as a %LET statement or a CALL SYMPUT)? One thing that you could find out about referencing SAS Macro variables is that they will not resolve correctly unless they are enclosed in double (") quotes. So unless you are creating a literal string of '&directory' as the value for your directory data step variable, my suspicion is that your program is not working as you expect.

In addition, this may be problematic:

datalogread;

because usually the keyword DATA is separated from the dataset name by a space. So your code could be:

DATA logread; or DATA log read; depending on whether you were creating 1 dataset in the WORK library or 2. Or, I suppose that LOG could be your LIBRARY and this is a possibility: DATA LOG.READ; -- it really depends on what you expect to be the output of the program.

cynthia

Kurt_Bremser
Super User

Actually this is not a macro at all, just a datastep that looks for files in given directory that were created after a given date, using the SAS file and directory I/O functions.

The directory name and the date are obviously specified somewhere farther "up" in the code.

To understand this, look at the documentation of the functions involved.

And there are a lot of syntax and semantic errors.

- datalogread should be data logread

- the format statement will not work, as the format spec is missing the dot

- dye is in the keep list and in a condition, but never has a value assigned (is always missing)

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 4 replies
  • 984 views
  • 0 likes
  • 4 in conversation