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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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