Hello,
How can I use a PROC SQL to select only variables from a SAS table which start with a prefix?
For example:
PROC SQL;
create table1 as
select a.prefix:,
from table2 as a;
QUIT;
Hi @markc
I would be surprised if somebody like PGstats might come up with something as I don't think Proc sql supports variable lists. This means you would have to query dictionary tables and load the varlist in macro separated by ',' and call in a select clause.
Ok that being said you could use keep= dataset option like-->
data w;
array t(10)(10*35);
j=57665;
run;
proc sql;
create table want as
select *
from w(keep=t:);
quit;
You have to spell out each variable when using SQL. There are ways to get macro language to save you some of the typing, but macro language would have to generate a program that lists each variable.
Of course, if you switch to a DATA step, the coding is easy:
data want;
set have (keep=prefix: ) ;
run;
You could use sashelp.vcolumns :
proc sql noprint;
select name into :cols separated by ","
from sashelp.vcolumn
where libname="SASHELP" and upcase(memname)="HEART" and
prxmatch("/^s/i", name) ;
create table subset as
select &cols.
from sashelp.heart;
quit;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.