I am trying to conditionally drop variables from a data set.
%macro drop_correlated(data_set);
%macro dummy; %mend dummy;
proc corr data=&data_set. pearson NOPROB nomiss Rank NoProb outp=correlations;
run;
data reduced;
set correlations;
where _TYPE_ = "CORR";
run;
data reduced;
set reduced;
drop _TYPE_;
run;
data _null_;
set reduced;
call symput(cat('VAR_',_N_),compress(trim(left(_NAME_))));
call symput('NUM_VAR',_N_);
run;
%local i;
%do i=1 %to &NUM_VAR.;
data temp_&i.;
set reduced;
where _name_ = "&&VAR_&i.";
drop _name_;
run;
%local j;
%do j=1 %to &NUM_VAR.;
data temp_&i.;
set temp_&i.;
if (-0.5 <= &&VAR_&j. <= 0.5) then %drop_var(temp_&i, &&VAR_&j.);
run;
%end;
%end;
%put _ALL_;
%mend drop_correlated;
%macro drop_var(data_in, var);
%macro dummy; %mend dummy;
data &data_in.;
set &data_in.;
drop &var.;
run;
%mend drop_var;
%drop_correlated(data);I get the error:
ERROR 180-322: Statement is not valid or it is used out of proper order.
I think this is coming from the drop_var macro.
You are trying to call a data step conditionally from a data step. You can't do that.
What you want to do is nonsense, your code would be equivalent to
data temp;
set temp;
if (-0.5 <= var <= 0.5) then drop var;
run;
Drop is a non-conditional statement. You can't drop a variable for a specific row, only for the whole dataset.
The data set only has one row though.
Please post example test data in the form of a datastep:
And show what you want out at the end. i would guess a data _null_ to create the list then a drop would be best, something like (assumes missing is to be dropped):
data _null_;
length dlist $2000;
set have;
array c{*} _character_;
array n{*} _numeric_;
do over c;
if missing(c) then dlist=catx(" ",dlist,c);
end;
do over n;
if missing(n) then dlist=catx(" ",dlist,n);
end;
call symputx('dlist',dlist);
run;
data want;
set want (drop=&dlist.);
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.