BookmarkSubscribeRSS Feed
George_SAS
Obsidian | Level 7

Hi everyone,

 

I have performed a load process in SAS and I am hardly trying to copy a set of files of a /directory1 into a different directory, but I am facing a problem to implement this action with a simple if condition, since I need to copy these files into a /directory2 when the variable trans_rc is equal to 0 and into a /directory3 when the variable trans_rc is different from 0.

 

I am trying the following code, but it does not copy the files when the variable trans_rc is different from 0 (i.e. when the load process finishes with errors):

 

%macro skip(trans_rc,
in,
out,
);

%put **&=trans_rc.**;
%if (&trans_rc. ne 0) %then %do;
  data _null_;
    rc = filename("_IN_", &in.);
    if rc = 0 and fexist("_IN_") then
      do;
        rc = filename('_OUT_',&out.);
        rc = fcopy("_IN_", '_OUT_');      
        rc = fdelete("_IN_"); rc = filename('_OUT_');
      end;
  rc = filename("_IN_");  run;
%end;
%mend skip;

%skip(&trans_rc.
,'/directory1/file1'
,'/directory3/file1'
)

%skip(&trans_rc.
,'/directory1/file2'
,'/directory3/file2'
)

However, when the load process is completed without any error, then the following code works fine and the files are appropriately copied into the corresponding directory:

 

%macro skip(trans_rc,
in,
out,
);

%put **&=trans_rc.**;
%if (&trans_rc. eq 0) %then %do;
  data _null_;
    rc = filename("_IN_", &in.);
    if rc = 0 and fexist("_IN_") then
      do;
        rc = filename('_OUT_',&out.);
        rc = fcopy("_IN_", '_OUT_');      
        rc = fdelete("_IN_"); rc = filename('_OUT_');
      end;
  rc = filename("_IN_");  run;
%end;
%mend skip;

%skip(&trans_rc.
,'/directory1/file1'
,'/directory2/file1'
)

%skip(&trans_rc.
,'/directory1/file2'
,'/directory2/file2'
)

Any idea?

6 REPLIES 6
tomrvincent
Rhodochrosite | Level 12

I got a chuckle reading that you're 'hardly trying' 🙂

Why not just add an %else block to the 2nd macro to handle non-zero values of trans_rc?

I'd also add a 4th parameter to handle the non-zero destination (/directory3/file1)

George_SAS
Obsidian | Level 7

I had already tried the else condition in the 2nd macro but it does not work. Indeed, as mentioned above, the 1st macro is not copying the files, so it is trivial to know that the else condition does not work despite of your note.

 

Why isn't the 1st macro working?

tomrvincent
Rhodochrosite | Level 12
'So trivial'? If it's 'so trivial' why not add some %puts after each statement to see where it's failing? You haven't pointed out just *where* it's failing.
George_SAS
Obsidian | Level 7

I had already added %puts after that but I can't reach the appropriate code to carry out this task and your previous note about the %else condition does not work, that is a trivial fact.

 

Any idea?

Tom
Super User Tom
Super User

What do you mean by variable TRANS_RC?

There are no variables with that name that I see.  The only variable I see is named RC.

 

Are you talking about the macro variable TRANS_RC?  There are TWO macro variables with that name.

One is the local macro available used as the input parameter name.

The other is the value you are passing in the call to the macro.

 

But I don't see that you giving the one you are passing into the macro a value anywhere.

 

George_SAS
Obsidian | Level 7

I am referring to a macro variable for status handle:

 

http://support.sas.com/documentation/cdl/en/etlug/60948/HTML/default/viewer.htm#p0p2c5hzlgy6acn18ql0...

 

I just want to implement a copy of files into a /directory2 if the job is completed without errors and into a /directory3 if the job finds any error (for example, if some datasets violate the referential integrity of a table, since my job represents a load process), just this.

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
  • 6 replies
  • 1492 views
  • 0 likes
  • 3 in conversation