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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.