BookmarkSubscribeRSS Feed
OS2Rules
Obsidian | Level 7

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;

data_null__
Jade | Level 19

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.

data test;
   input testvar $80.;
  
cards4;
Not to worry about EBCDIC or DBCS - the whole thing is in ASCII.
Your solution looks interesting.... I will give it at try as time permits and let you know.
(also - my IBM System/370 Reference Summary GX20-1850-3 circa 1976 spells it:  EBCDIC)
%macro counter(data=,var=);
   data work01(keep=char);
      attrib char length=$1. format=$char1.;
      set &data(keep=&var);
      where not missing(&var);
      do i=1 to length(&var);
         char = char(&var,i);
         if findc(char,' .','AKI') then output;
         end;
      run;
   proc freq data=work01;
      table char / list missing;
      run;
   %mend;
%counter(data=test,var=testvar)
;;;;;
   run;

%macro counter(data=,var=);
   data work01(keep=char);
      attrib char length=
$1. format=$char1.;
      set &data(keep=&var);
      where not missing(&var) and findc(&var,
' .','ADKI');
      do i=1 to length(&var);
         char = char(&var,i);
         if findc(char,
' .','ADKI') then output;
         end;
      run;
   proc freq data=work01;
      table char / list missing;
      run;
  
%mend;
%
counter(data=test,var=testvar);

10-24-2014 8-40-06 AM.png
erickbernard
Calcite | Level 5

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 17 replies
  • 2216 views
  • 1 like
  • 6 in conversation