2012-10-02 4 views
1

는 다음과 같은 고려 :왜 MAX 함수는 proc sql에서 SAS 변수 형식을 제거합니까?

data; 
format x datetime19.; 
x=datetime(); 
flag='FIRST'; 
do x=datetime() to x+10 by 1; 
    output; 
    flag=''; 
end; 
proc sql noprint; 
select x into : test1 from &syslast where flag='FIRST'; 
select max(x) into: test2 from &syslast; 
%put now we see that &test1 is in a different format to &test2; 

data _null_; set; 
put x=; /* formatted */ 
call symput('test3',x); 
call symput('test4',max(x,sum(x+1000))); 
stop; 
run; 
%put The data step is more consistent - &test3 = &test4; 

가 나에게 일관성 보인다. 이 경우 proc sql에서 형식을 유지하는 이유는 무엇입니까? 이 행동이 문서화되어 있습니까?

답변

3

SAS는 함수 결과를 어떻게 포맷해야하는지 알 수 없습니다. 이 경우 귀하의 max() 함수는 단순히 datetime을 반환하지만, 내부에 중첩 된 함수 나 산술 연산이 있다면 어떻게 될까요? 이 때문에 SAS는 기본적으로 형식을 설정하지 않은 새로운 변수로 취급합니다. 당신이 동일한 서식을 적용하려는 경우 당신이 당신의 코드를 변경할 수 있습니다 귀하의 예제에서

select max(x) format=datetime19. into: test2 from &syslast; 
+0

- 당신이 리차드의 매크로를 수정할 수 있습니다 (http://www.devenezia.com/downloads/sas/macros/index.php?m=samelabl) 한 데이터 세트의 형식을 다른 데이터 세트로 복사 할 수 있습니다. –

+0

함수가 의미가 있습니다. 데이터 단계 결과도 설명합니다 (symput 함수). –

2

을의 MAX 함수는 새 열을 생성하고 새 열을 만들 때, 당신은 모든 열 속성을 지정해야 . 그래서, 당신의 선택 문에 FORMAT 절을 추가 : 또한

proc sql noprint; 
    select x into : test1 from &syslast where flag='FIRST'; 
    select max(x) format=datetime19. into: test2 from &syslast; 
quit; 
%put now we see that &test1 is in a different format to &test2;