Hi all,
I have a dataset with ~100 variables and I want to drop 30 of them. Those 30 happen to have similar variable names (eg XXX_flag).
I want to find a way to drop those 30 variables highlighted in red below and I tried using (drop= :_flag) but it doesn't work.
Is there a shorter way to drop all those flags?
Below are examples of my variables:
Name
Address
Member
State
City
Zipcode
Country
.... /*Many many other demographics variables*/
Apple_flag
Banana_flag
Pear_flag
Orange_flag
Coconut_flag
..../*Many many other _flags*/
Apple_sum
Banana_sum
Pear_sum
..../*Many other _sum*/
Hi,
PLease use the search functionality, I posted something about this some days back and there are many examples, e.g.:
https://communities.sas.com/message/234505#234505
Query the SAS metadata in sashelp.vcolumn, generate a macro variable then drop those on the macro variable.
A macro from the SUGI 30 paper 029-30 Text Utility Macros for Manipulating Lists of Variable Names by Robert J Morris might help:
%macro parallel_join(words1, words2, joinstr, delim1=%str( ), delim2=%str( ));
%local i num_words1 num_words2 word outstr;
%* Verify macro arguments. ;
%if (%length(&words1) eq 0) %then %do;
%put ***ERROR(parallel_join): Required argument 'words1' is missing.;
%goto exit;
%end;
%if (%length(&words2) eq 0) %then %do;
%put ***ERROR(parallel_join): Required argument 'words2' is missing.;
%goto exit;
%end;
%if (%length(&joinstr) eq 0) %then %do;
%put ***ERROR(parallel_join): Required argument 'joinstr' is missing.;
%goto exit;
%end;
%* Find the number of words in each list. ;
%let num_words1 = %num_tokens(&words1, delim=&delim1);
%let num_words2 = %num_tokens(&words2, delim=&delim2);
%* Check the number of words. ;
%if (&num_words1 ne &num_words2) %then %do;
%put ***ERROR(parallel_join): The number of words in 'words1' and;
%put *** 'words2' must be equal.;
%goto exit;
%end;
%* Build the outstr by looping through the corresponding words and joining
* them by the joinstr. ;
%let outstr=;
%do i = 1 %to &num_words1;
%let word = %scan(&words1, &i, &delim1);
%let outstr = &outstr &word&joinstr%scan(&words2, &i, &delim2);
%end;
%* Output the list of joined words. ;
&outstr
%exit:
%mend parallel_join;
use in your drop statement
(drop = %parallel_join(apple pear banana , _flag ) )
since you still need to provide the stems I'm not sure it'll help much from copy and paste unless you are also processing other suffixes at the same time such as _sum _max _min and such.
How about a modern approach using DOSUBL?
Hi,
PLease use the search functionality, I posted something about this some days back and there are many examples, e.g.:
https://communities.sas.com/message/234505#234505
Query the SAS metadata in sashelp.vcolumn, generate a macro variable then drop those on the macro variable.
⏰
Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.
Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.