Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statgeek/dd57887f1d34f3dc6476471d9ac035ed to your computer and use it in GitHub Desktop.
Save statgeek/dd57887f1d34f3dc6476471d9ac035ed to your computer and use it in GitHub Desktop.
SAS - dynamically generate a list for filtering
/*
One common issue with using SQL pass through is that you sometimes want to use data that is on your SAS server. Rather than pass this information to the server, to be used in a subquery or join, you can pass the values directly by dynamically generating the code and lookup lists
*/
%let age = 14;
data test;
set sashelp.class end = eof;;
where age = &age.;
if _n_ =1 then do;
call execute('proc sql; select * from sashelp.class where name in (');
end;
if not eof then do;
call execute(quote(name));
call execute(",");
end;
if eof then do;
call execute(quote(name));
call execute("); quit;");
end;
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment