Drop columns that contain '$$' or '('
inspired by
https://goo.gl/2GydUH
https://communities.sas.com/t5/Base-SAS-Programming/Remove-columns-with-characters/m-p/335357
HAVE
====
Up to 40 obs WORK.HAVE total obs=1
Obs DATE TRACKING COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8
1 01/01/16 2z. $$ bag. Atm. { BAG. STM $$ {
WANT
====
Up to 40 obs WORK.WANT total obs=1
bs DATE TRACKING COL2 COL3 COL5 COL6
1 01/01/16 2z. bag. Atm. BAG. STM
DETAILS
=======
COL1='$$' so drop
COL7='$$' so drop
WORKING CODE
============
rc=dosubl('
if chrs[i]="$$" then rol=catx(" ",rol,vname(chrs[i]));
call symputx("drp",rol);
set have(drop=&drp);
FULL SOLUTION
=============
Create some data;
data have;
input (Date Tracking Col1 col2 col3 col4 col5 col6 col7 col8) ($);
cards4;
01/01/16 2z. $$ bag. Atm. { BAG. STM $$ {
;;;;
run;quit;
%symdel drp;
data want;
if _n_=0 then do;
rc=%sysfunc(dosubl('
data out;
length rol $200;
do until (dne);
set have end=dne;
array chrs[*] col:;
do i=1 to dim(chrs);
put chrs[i] ;
if chrs[i]="$$" or chrs[i]="{" then rol=catx(" ",rol,vname(chrs[i]));
end;
end;
call symputx("drp",rol);
stop;
run;quit;
'));
end;
set have(drop=&drp);
drop rc;
run;quit;
Please show data before and after.
What you have and want isn't clear from what you've shown. Provide the have and want example in the form of two data steps.
Art, CEO, AnalystFinder.com
Drop columns that contain '$$' or '('
inspired by
https://goo.gl/2GydUH
https://communities.sas.com/t5/Base-SAS-Programming/Remove-columns-with-characters/m-p/335357
HAVE
====
Up to 40 obs WORK.HAVE total obs=1
Obs DATE TRACKING COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8
1 01/01/16 2z. $$ bag. Atm. { BAG. STM $$ {
WANT
====
Up to 40 obs WORK.WANT total obs=1
bs DATE TRACKING COL2 COL3 COL5 COL6
1 01/01/16 2z. bag. Atm. BAG. STM
DETAILS
=======
COL1='$$' so drop
COL7='$$' so drop
WORKING CODE
============
rc=dosubl('
if chrs[i]="$$" then rol=catx(" ",rol,vname(chrs[i]));
call symputx("drp",rol);
set have(drop=&drp);
FULL SOLUTION
=============
Create some data;
data have;
input (Date Tracking Col1 col2 col3 col4 col5 col6 col7 col8) ($);
cards4;
01/01/16 2z. $$ bag. Atm. { BAG. STM $$ {
;;;;
run;quit;
%symdel drp;
data want;
if _n_=0 then do;
rc=%sysfunc(dosubl('
data out;
length rol $200;
do until (dne);
set have end=dne;
array chrs[*] col:;
do i=1 to dim(chrs);
put chrs[i] ;
if chrs[i]="$$" or chrs[i]="{" then rol=catx(" ",rol,vname(chrs[i]));
end;
end;
call symputx("drp",rol);
stop;
run;quit;
'));
end;
set have(drop=&drp);
drop rc;
run;quit;
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.