Hi folks:
I have the following varlists (_effectentered and _effectremoved).
I want to have another varlist (_stdvar) which excludes &_effectremoved from &_effectentered.
I tried the following code but the problem is that x2 will be dropped from x23 as well.
%let _EffectEntered = x1 x2 x3 x23 ;
%let _EffectRemoved = x2 x3 ;
%let _stdvar=%sysfunc(prxchange(s/%sysfunc(translate(&_EffectRemoved,%str(|),%str( )))//,-1,&_EffectEntered));
%put &_stdvar ;
would you please help me in this regard?
Thanks
Hi Moh,
Good idea to use PRXCHANGE here, so you can perform this fairly complex operation within the %LET statement.
I think you should insert word boundary metacharacters and put the "or" expression in parentheses to make sure that only complete words are replaced, not substrings of longer words:
%let _stdvar=%cmpres(%sysfunc(prxchange(s/\b(%sysfunc(translate(&_EffectRemoved,%str(|),%str( ))))\b//,-1,&_EffectEntered)));
%put &_stdvar;
The %CMPRES function (or macro) replaces multiple blanks by single blanks.
Hi Moh,
Good idea to use PRXCHANGE here, so you can perform this fairly complex operation within the %LET statement.
I think you should insert word boundary metacharacters and put the "or" expression in parentheses to make sure that only complete words are replaced, not substrings of longer words:
%let _stdvar=%cmpres(%sysfunc(prxchange(s/\b(%sysfunc(translate(&_EffectRemoved,%str(|),%str( ))))\b//,-1,&_EffectEntered)));
%put &_stdvar;
The %CMPRES function (or macro) replaces multiple blanks by single blanks.
Thanks so much
Essentially, this will be the same problem as one that was recently answered:
https://communities.sas.com/t5/SAS-Data-Management/How-to-merge-two-varlists/m-p/242534
Assuming that it is OK to uppercase the variable names:
%let _stdvar=;
%let _EffectEntered = %upcase(&_EffectEntered);
%let _EffectRemoved = %upcase(&_EffectRemoved);
%do i=1 %to %sysfunc(countw(&_EffectEntered));
%let nextone = %scan(&_EffectEntered, &i);
%if %index( %str( &_EffectRemoved ), %str( &nextone )) = 0 %then %let _stdvar = &_stdvar &nextone;
%end;
The usual warnings apply. You will need to define a macro since the code uses %IF. In that case, you need to pay attention to which macro variables are local and which are global.
Good luck.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: