Hello, I want to write a script to sum all ascii values by the column on SAS dataset and a script sample like follows. Actually, the script can be run normally with generate result successfully. But I face a problem that the performance is very slow if the number of selections are over milliion. Could some one help me to settle the performance issue? Many thanks! %macro sqlloop; %LET numrecords = 0; PROC SQL noprint; select count(*) into :numrecords from test.convertsac where flag='Y' and tab_name like 'TB_%%'; quit; %if &numrecords>0 %then %do; PROC SQL noprint outobs=&numrecords; select tab_name, col_name into :tab1 - :tab%left(&numrecords), :col1 - :col%left(&numrecords) from test.convertsac where flag='Y' and tab_name like 'TB_%'; %DO x=1 %TO &numrecords; %let tbname = &&tab&x ; %let colname = &&col&x ; select count(*) into :numobs from test.&tbname where &colname is not null; quit; %PUT &tbname &colname =======START========; %LET totalasc = 0; %if &numobs>0 %then %do; PROC SQL noprint outobs=&numobs; select &colname into :tmp1 - :tmp%left(&numobs) from test.&tbname where &colname is not null; %DO k=1 %TO &numobs; %LET STRING= %sysfunc(TRIM(&&tmp&k)); %LET ascsum = 0; %do i = 1 %to %length(&STRING); %let ischara=%substr(&STRING,&i,1); %let ischara=%str(&ischara); %let asc =%sysfunc(rank(%bquote(&ischara))); %if &asc=0 %then %do; %let asc =32; %end; %let ascsum=%eval(&ascsum + &asc) ; %end; %LET totalasc=%eval(&totalasc + &ascsum) ; %END; %PUT &tbname &colname &totalasc =======END======== PROGRESS= &x / &numrecords; %end; %else %do; %PUT &tbname &colname &totalasc =======END======== PROGRESS= &x / &numrecords; %end; PROC SQL noprint; update test.convertsac set ascii=&totalasc, flag='N' where tab_name ="&&tbname" and col_name="&&colname"; %END; %END; QUIT; %mend; %sqlloop;
... View more