Your SAS programs, embedded in web apps and elsewhere

Create a select stamenet from multiple selection input field from a Stored Process

Accepted Solution Solved
Reply
Highlighted
Contributor
Posts: 49
Accepted Solution

Create a select stamenet from multiple selection input field from a Stored Process

Hey,

 

I'm on SAS 9.4M2

I have a Stored Process that has three Inputs and one of them is a dynamic list from which the user can choose multiple inputs. What I want to do is take these multiple inputs and use them in a select statement for a proc sql later in the programm. The input variable as the name var.

My thought was to concatenate the input arguments with a.&var1, a.&var2, .... I tried doing this like this:

 

%do i = 1 %to &var0;
            %let newvar1 = var&i;
           %let var = "&var, a.&&newvar1";
%end;

So I try to append the current value var with the next value until there are no more values.

 

The do-loop executes correct but the second let-statement doesn't work as intended. Can somebody please point me in the right direction of what I'm doing wrong!

 

Thanks in advance

David


Accepted Solutions
Solution
3 weeks ago
Contributor
Posts: 49

Re: Create a select stamenet from multiple selection input field from a Stored Process

So I did some further digging in some SAS notes and have now found a solution that works fine for me and I'm posting it here for somebody with a similar problem.

 

%let var = a.&var1;
%do I = 2 %to &var0;
        data _null_;
	    length building $500.;
	    building = trim(catt("&var", ", a.&", "var", &I));
            call symput('var', building);
        run;
%end;

I'm looping over the data step and use the data step to the work with the string inside of the data step.

 

Output looks like this: a.value1, a.value2, .....

The first let statement is necassry to append the string correctly.  The trim function is not necassry, but I always like including it when working with strings.

View solution in original post


All Replies
Solution
3 weeks ago
Contributor
Posts: 49

Re: Create a select stamenet from multiple selection input field from a Stored Process

So I did some further digging in some SAS notes and have now found a solution that works fine for me and I'm posting it here for somebody with a similar problem.

 

%let var = a.&var1;
%do I = 2 %to &var0;
        data _null_;
	    length building $500.;
	    building = trim(catt("&var", ", a.&", "var", &I));
            call symput('var', building);
        run;
%end;

I'm looping over the data step and use the data step to the work with the string inside of the data step.

 

Output looks like this: a.value1, a.value2, .....

The first let statement is necassry to append the string correctly.  The trim function is not necassry, but I always like including it when working with strings.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 155 views
  • 0 likes
  • 1 in conversation