-1

I am not sure if I get any answer on a saturday evening, but I will give a shout :)

I am trying to automize a SAS-code which does comparison in a viariable between 2-3 companies. In each task, I will probably work with different companies, so I guess I can only enter the company names manually.

I describe macro-variables for each company, for example:

%let C1=CompanyNo1; %let C2=CompanyNo2; %let C3=CompanyNo3;

and then I only put &C1 in the remaining code. If I work for another company no later, then I only change the CompanyNo1 in the code.

However, the problem is that I may need to do the comparison between different number of companies later. If I write the code for 4 companies, and if I need to do the comparison between 2 companies in the next run, then I have to deactivate some part of the code.

So I want to write an existince check in the code like;

data _null_; if &C3 is true then continue the run; else if quit the code. run;

Someone told me that I can do that with %Macro statement(he said maybe, he wasn't sure). But I am not sure how to achieve this with %Macro.

Thanks for any contribution in advance...

user3714330
  • 679
  • 12
  • 32
  • Have a look at [this question](http://stackoverflow.com/questions/9009944/is-there-a-way-to-make-sas-stop-upon-the-first-warning-or-error/9217932#9217932) - it's not quite the same as yours, but the solutions offered could easily be adapted. – user667489 Jun 20 '15 at 21:05
  • Thanks for the link. Now I don't have my original code and SAS program, but it might help somehow. That link opens up another question: Is it possible to implement that into %Macro whitout getting any error message? For instance, I write the "data-run statement" as usual for first two companies, but I write the "data-run" statement in that %Macro check for the third company(&C3), like: %macro check_for_errors; %data table3; % process=&C3 some bla bla process...; %run; %if &syserr > 0 %then %do; endsas; %end; %mend check_for_errors; – user3714330 Jun 20 '15 at 21:32
  • Your question is vague, and without knowing what you're doing inside the macro or how you're comparing it's hard to suggest alternatives. You can easily write loops to handle the macro variables until it encounters missing values. – Reeza Jun 21 '15 at 00:08

2 Answers2

1

You can check for existence of macro variables in your code with the %SYMEXIST macro function and SYMEXIST data step function.

Stig Eide
  • 1,052
  • 7
  • 14
0

Finally I found an effective solution.

%Macro checking;
  %let C3=CompanyNo3;
  %if &SYSERR > 0 %then %do;
     %goto exit;
  %end;

  'other data processes here';

  %exit:   /* Be careful, it is not semicolon  */
 %Mend;

So if there is no CompanyNo3, then SAS gives only a warning that CompanyNo3 is not attended. Then it goes to exit, it doesn't do other data processes. It finalizes the process without error message.

user3714330
  • 679
  • 12
  • 32