Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping/Dropping Variables in SAS

Tags:

sas

I want to remove columns/variables from a large SAS dataset, call it 'data'. I have all of the column names that I want to drop stored in another SAS dataset - let's call it 'var', it has a single column with header column. How do I drop all of the variables contained in 'var' from my original dataset 'data' with the drop function?

Thanks!

like image 364
Michael Avatar asked Dec 21 '22 08:12

Michael


1 Answers

You can use the "into" clause of proc sql to copy the column of variable names from the "vars" data set into a macro variable that you then pass to the drop= statement in a data step. See below:

proc sql noprint;
  select <name_of_column> into: vars_to_drop separated by " "
  from var;
quit;

data data;
  set data (drop= &vars_to_drop);
run;
like image 92
fscmj Avatar answered Jan 01 '23 15:01

fscmj