I have done the following dummy case where I input a condition in a specific dataset as following:
%macro filterDataOneCondition(name, dataset, condition);
proc sql;
CREATE TABLE &name AS
SELECT *
FROM %sysfunc(dequote(&dataset ))
where make = %sysfunc(dequote(&condition));
quit;
%mend;
%filterDataOneCondition(name = table1, dataset = sashelp.cars, condition= "'Acura'");
run;
Now what I want to get is
(1) indexing different names in an array and loop to get the same answer as before but for all variables in the array
(2) is there a function to know the length of an array instead of specifying it by hand ?
Conditions: no usage of iml neither rlang.
My trial is as following:
%let Make1= "'Acura'";
%let Make2= "'Acura'";
%let Make3= "'Acura'";
%let name1= 1;
%let name2= 2;
%let name3= 3;
%let ARRAYMake= array(&Make1 &Make2 &Make3);
%let ARRAYNAME= array(&name1 &name2 &name3);
%let lenarray = 3; * How to get a function that gives me len(ARRAYMake)?;
DO i = 1 to &lenarray;
%filterDataOneCondition(name = ARRAYMake{i}, dataset = sashelp.cars, condition= ARRAYNAME{i});
run;
end;
EDIT:
As a summary, what I am trying to achieve with this post is:
(1) Understanding how to create an array of variables from some that are already existing. That is why I am trying the thing about:
% let Make1 = Audi;
% let Make2 = BMW;
%let Arraymake = Make1 Make2 * This is what I wanted :)
(2) Understanding how to define directly the length of a vector or an array (i.e. analogy of the function length() in R or len() Python)
/*Calculating the lenght of an array*/
%let lenarray = %sysfunc(countw(&arraymake)); * This what I wanted;
(3) What I am still trying is to avoid writing the code below and instead passing a loop to the list of variables:
How to iterate a same procudure to create directly different outputs instead of having to write
%filterDataOneCondition(name = Make1, dataset = sashelp.cars, condition= name1);
run;
%filterDataOneCondition(name = Make2, dataset = sashelp.cars, condition= name2);
run;
%filterDataOneCondition(name = Make3, dataset = sashelp.cars, condition= name3);
run;
but in a do loop
Thank you for the help and the time spent in advanced