1. Import your Excel file, I'm going to assume you know how to do this.
2. Create a list of the variables using a macro variable
3. Use the macro variable
It really does depend on how the 'empty' variable data set is structured, though.
proc sql noprint;
select varName into :keep_list separated by " "
from importFromExcel;
quit;
data want;
set t1 (keep = &keep_list)
t2 (keep = ID ....other variables *optional*);
run;
@JayceWaylon wrote:
Is there a way to keep variables from one dataset if I am setting multiple datasets? There is an excel file of the variables that is wanted, it is only variables no data. Then I have my raw data that has the variables but has the data. I want to have a new dataset where I can set my “wanted variables” with my “raw data variables” and just keep those variables, because the raw data will have more variables than wanted.
I know I can do a simple keep statement, I am wanting it to be dynamic, so if the excel file with the desired variable list changes the new dataset will catch it and keep the new added variable. Rather than checking all the variables each time.