Hi,
I have a big data set with more than 4000 columns and need to keep columns that have specific sequence of characters in their name (e.g. "_US_"). Can I that using wildcards in "Keep" statement?
thank you
Hello,
If the sequence is in the middle of the character name you can select those variable in a macro statement separated by space and
use this macro variable in a keep statement.
For doing this operation you shall use the dictionary table - vcolumn:
proc sql;
select name into :vr separated by ' '
from sashelp.vcolumn
where libname eq 'SASHELP' and memname eq 'CLASS'
and name like '%h%';
quit;
data want;
set sashelp.class;
keep &vr;
run;
Hi,
On a similar pattern as per @Loko suggestion:
proc contents data=have out=vars(keep=name);
run;
proc sql;
select name into :vars_needed separated by ' '
from vars
where find(name,"_US_")>0;
quit;
%put &vars_needed;
I really thank all of you for you replies,
The solution using proc sql worked fine,
(I was just wondering if a more ''complex'' KEEP statement could do the job but it seems there is no such possibility)
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.