Hi All (again):
After a little fine tuning, this is what I came up with.....
%macro counter (var_name);
data work01;
attrib char length=$1. format=$char1.;
set worklib.primebase_last_client (keep=&var_name);
if &var_name ne: '' then do i=1 to length(&var_name);
char = upcase(substr(&var_name,i,1));
if indexc(char,'ABCDEFGHIJKLMNOPQRSTUVWXYZ') = 0 then output;
else delete;
end;
drop &var_name i;
run;
proc freq data=work01;
table char / list missing;
run;
%mend;
I don't think you want ELSE DELETE in that context. I modified your program slightly to use FINDC. I also added digits, space and '.' to the list of good characters but you may not want that. You could make the character list a parameter to the macro.
well hopefully I'm not cluttering this thread by another post. Anyway, I had a similar problem some time ago, and my solution was to summarize data first, then remove all the legal characters. here's my sample code (using the testdata above, unfortunately I can't paste from SAS window, and hence the ugly formatting, sorry about that);
/*first summarize data*/
proc sort data=test by testvar; run;
proc summary data=test; by testvar; output out=test2(drop=_type_);run;;
/*then remove "legal" characters*/
data test3; set test2;
original=testvar;
testvar=upcase(testvar);
testvar=compress(testvar,"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.