libname anylib "E:\";
data anylib.table1;
length aayyy eeeeee abcjjjjj bbcjjjjj abcdejd 8;
run;
data work.table2;
length aayyy abcjjjjj bbcjjjjj abcdejd 8;
run;
proc sql;
create table list as
select * from (
select libname, memname, name,
case
when
compress(substr(name, 3), substr(name, 3, 1)) = ''
then catt(substr(name, 1, 2), '_', substr(name, 3))
when
compress(substr(name, 4), substr(name, 4, 1)) = ''
then catt(substr(name, 1, 3), '_', substr(name, 4))
else '' end
as newname
from dictionary.columns
where libname in ('WORK', 'ANYLIB') and length(name) >= 5
and (substr(name, 3, 1) = substr(name, 4, 1)
or substr(name, 4, 1) = substr(name, 5, 1)
)
) where newname is not null
order by libname, memname
;
quit;
data _null_;
set list;
length stmt $200;
file "E:\renames.sas";
by libname memname;
if first.libname then do;
stmt = 'proc datasets lib=' || libname || 'nolist nodetails;';
put stmt;
end;
if first.memname then do;
stmt = 'modify ' || memname || ';';
put stmt;
stmt = 'rename';
put stmt;
end;
stmt = ' ' || name || ' = ' || newname;
put stmt;
if last.memname then do;
stmt = ';';
put stmt;
end;
if last.libname then do;
stmt = 'quit;';
put stmt;
end;
run;
%include "E:\renames.sas";
compress(substr(
뒤에 아이디어는 ... 3 또는 4 문자가 이름의이 끝날 때까지 반복 이름을 찾는 것입니다. 그런 다음 데이터 단계에서 PROC DATASETS
이라는 스크립트를 생성하고 실행합니다 (% 포함).
여기에서 자세한 정보가 필요합니다. 현재 코드와 예제 데이터를 보여줄 수 있습니까? – Joe
"_"이 삽입되는지 여부를 결정하는 패턴의 명시 적/공식적인 아이디어없이 명시 적으로 대답하기가 어려울 것입니다. 어느 쪽이든, 나는 패턴이이 단계에서 나에게 꽤 불규칙하게 보이는 perl 정규 표현식 (PRX) 함수를 살펴볼 필요가 있다고 생각한다. % SYSFUNC() 매크로 함수를 통해 매크로 코드에서 사용할 수 있습니다. 각 단어 위에 PRX 패턴을 반복하여 일치 여부에 따라 변경할 수 있습니다. – DJM