2014-10-17 3 views
1

나는 많은 종류가 있습니다 agegroup라는 변수, 예를 : 1 = "0-5"2 = "6-10"등SAS는 제목에 변수 형식을 넣어

나는 데이터를 인쇄하는 매크로를 작성하는 경우 agegroup으로 제목에 연령 그룹 형식을 갖고 싶다면 어떻게해야합니까?

%macro ageprint(agegrp=1); 
proc print data=age; 
title "Age group &agegrp"; 
run; 
%mend; 

이 매크로를 실행하면 제목을 "연령 그룹 1"대신 "나이 그룹 0-5"로 인쇄하고 싶습니다.

누구든지 힌트가 있으십니까?

감사합니다.

답변

2

이와 비슷한?

proc format ; 
value grpformat 
     0 - 5 = '0 - 5' 
     6 - 10 = '6 - 10' 
     other = 'other' 
      ; 
run; 

%macro ageprint(agegrp); 
proc print data=age; 
    where agegrp=&agegrp; 
title "Age group %sysfunc(putn(&agegrp, grpformat.))"; 
run; 
%mend; 

%ageprint(agegrp=2); 
%ageprint(agegrp=8); 
+0

고마워요! 이것은 아주 잘 작동합니다! – ponyhd

3
당신은이 제목에 형식이 지정된 값을 취뿐만 아니라 #byval (나이) 옵션을 사용할 수 있습니다

: 당신이 매크로를 필요로하는 경우

proc format ; 
value grpformat 
     0 - 12 = '0 - 12' 
     12 - 14 = '12 - 14' 
     other = 'other' 
      ; 
run; 

proc sort data=sashelp.class out=class; by age; run; 

proc print data=class; 
by age; 
format age grpformat.; 
title "Age Group #byval(age)"; 
run; 

당신은 여전히 ​​같은 방법을 사용할 수 있습니다 출력이 어디로 가는지 예 :

%macro ageprint(agegrp=1); 
proc print data=age; 
by agegrp; 
title "Age group #byval(agegrp)"; 
run; 
%mend; 
+0

안녕하세요 Reese, 답장을 보내 주셔서 감사합니다. 내 매크로에서 해결책을 시도했지만 '#byval'은 리터럴하게 인쇄되었습니다. 문제가 발생한 위치를 확인하십시오. – ponyhd

+0

코드가 잘 알려지지 않으면 proc에도 by를 포함시켜야합니다. – Reeza