BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Criptic
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
Criptic
Lapis Lazuli | Level 10

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

1 REPLY 1
Criptic
Lapis Lazuli | Level 10

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1 reply
  • 1107 views
  • 0 likes
  • 1 in conversation