SAS/SAS 질문과 답변
매크로를 활용한 변수 생성 관련 질문입니다.
이슈카
2016. 2. 20. 13:32
고수님들들께 도움을 요청합니다.
매크로를 사용하여
변수들을 일정한 법칙에 따라 곱하여 새로운 변수를 생성하고자 합니다.
데이터셋의 변수가 col1 col2 col3 col4 가 있을때
새로운 변수들은 다음과 같은 법칙에 따라 생성하고자 합니다.
col12=col1*col2 ;
col13=col1*col3 ;
col14=col1*col4 ;
col23=col2*col3 ;
col24=col2*col4 ;
col34=col3*col4 ;
고수님들께서 매크로 코드 작성에 도움을 주시기 바랍니다.
================================================================================
data temp;
input col1 col2 col3 col4;
cards;
1 2 3 4
;
run;
proc contents data=temp out=temp_o noprint;
run;
data _null_;
set temp_o end=eof nobs=cnt;
if eof then call symput('cnt',cnt);
run;
%macro make;
data temp1;
set temp;
%do i=1 %to &cnt;
%do j=1 %to &cnt;
col&i&j = col&i * col&j;
%if &i ne 1 %then %if &i = &j %then drop col&i&j;
;
%if &i ne 1 %then %if &i > &j %then drop col&i&j;
;
%end;
%end;
run;
%mend;
%make;