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
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.
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.