Your SAS programs, embedded in web apps and elsewhere

Looping through a set of parameters

Posts: 0

Looping through a set of parameters

I have a parameter that has several possible entries, i.e., for supervisors, the parameters that can be chosen can be up to 5 in total. To "pull in" the parameters and subsequently use them as part of an IN comparison in a PROC SQL, I have the following code:

To pull in the parameters:

%if &supvcodes0 = %str() %then %do;
%let supvcodesval = "&supervisorycodes";
%else %do;
%do i = 1 %to %supvcodes0;
%let supvcodesval = &supvcodesval " " "&&supvcodes&i";

To compare my data against the parameters in my PROC SQL:


Is this valid code and logic? The reason I ask is that it appears my code, as shown in a PROC REPORT, only hsows records for my first parameter value and not for other values in the same parameter. If there is a better way of doing what I'm attempting, would someone please respond?

Thanks in advance to any who reply....looking forward to your suggestions.
Posts: 8,743

Re: Looping through a set of parameters

These previous forum responses may be useful to you:׼ఐ

Generally when you are dealing with a test for a null macro variable the test is coded as:

%if &macvar =; (macro variable has a NULL value which means that, in your case, no value was sent by the client application to the server)
%if &macvar ne ; (macro variable has SOME value you don't yet know what)
%if %upcase(&macvar) eq WOMBAT %then %do; (when you compare a macro variable to a text string, you don't need quotes).

Have you coded and tested in PROC REPORT, what a working where statement would look like:
where somevar in ("val1", "val2", "val3"); ???

Posts: 0

Re: Looping through a set of parameters

Thank you for your timely response, Cynthia! I was quite close on my code, but I think your suggested links will put me onth tohe correct path. I appreciate you being so helpful, and I also appreciate your knowledge!
Ask a Question
Discussion stats
  • 2 replies
  • 2 in conversation