SAS 데이터 단계에서 데이터를 정렬하려고합니다. 정확히 말하면 proc 정렬 작업은 데이터 단계에서 수행되어야합니다. 어떤 해결책이 있습니까?SAS에서 데이터 단계를 사용하여 데이터를 정렬하는 방법
답변
데이터 단계 전용 솔루션을 찾으려면 PROC SORT
의 작업을 hash table과 함께 수행 할 수 있습니다. 주의 할 점은 당신이 그것을하기에 충분한 메모리가 필요하다는 것입니다.
간단한 정렬을 수행하려는 경우 ordered:'yes'
옵션을 사용하여 해시 테이블을로드하고이를 새 테이블로 출력합니다. 기본적으로 ordered:yes
은 오름차순으로 데이터를 정렬합니다. descending
도 지정할 수 있습니다.
간단한 분류
data _null_;
/* Sets up PDV without loading the table */
if(0) then set sashelp.class;
/* Load sashelp.class into memory ordered by Height. Do not remove duplicates. */
dcl hash sortit(dataset:'sashelp.class', ordered:'yes', multidata:'yes');
sortit.defineKey('Height'); * Order by height;
sortit.defineData(all:'yes'); * Keep all variables in the output dataset;
sortit.defineDone();
/* Output to a dataset called class_sorted */
sortit.Output(dataset:'class_sorted');
run;
multidata
옵션을 제거 제외하고는 동일한 작업을 수행 중복을 제거하려면
을 중복 제거. 아래 표에서 관측치 (8, 9)와 (15, 16)은 서로 중복됩니다. 관측 9와 16은 제거 될 것입니다.
data _null_;
/* Sets up PDV without loading the table */
if(0) then set sashelp.class;
/* Load sashelp.class into memory ordered by Height. Do not keep duplicates. */
dcl hash sortit(dataset:'sashelp.class', ordered:'yes');
sortit.defineKey('Height'); * Order by height;
sortit.defineData(all:'yes'); * Keep all variables in the output dataset;
sortit.defineDone();
/* Output to a dataset called class_sorted */
sortit.Output(dataset:'class_sorted');
run;
사용중인 proc ds2의 해결책이 있습니다.
/*Just prepare dataset, because DS2 responds with an error on libraries like sashelp. */
data sql_prep;
set sashelp.class;
run;
/*Delete test dataset before ds2 func, to avoid errors*/
proc datasets nodetails nolist;
delete test;
run;
proc ds2;
data test;
method run();
set {select * from sql_prep order by Weight};
end;
enddata;
run;
quit;
info 약 sshelp 라이브러리의 ds2 오류입니다.
Appendix을 ds2 docs로, 약 ds2의 SQL을
이것이 유효하다면'dosubl' 또한 공정한 게임이라고 생각합니다 ... – user667489
스투 그것에 나를 이길하지만 데이터 세트는 고유 키가 포함되어 제공, 당신은 메모리에 모든 것을 넣을 수, 당신은 해시 정렬, 예를 들어 사용할 수 있습니다
data _null_;
if 0 then set sashelp.class;
declare hash h(dataset:"sashelp.class",ordered:"a");
rc = h.definekey("age","sex","name");
rc = h.definedata(ALL:'yes');
rc = h.definedone();
rc = h.output(dataset:"class_sorted");
stop;
run;
하는 경우를 내장 된 정렬 방법을 사용하지 않기로 결정한 경우, 전체 데이터 세트를 일련의 임시 배열에로드하고, 직접 코딩 된 알고리즘을 사용하여 배열을 정렬 한 다음 다시 내 보내야합니다.
https://codereview.stackexchange.com/questions/79952/quicksort-in-sas-for-sorting-datasets
왜 그런 일을하고 싶은지 알고 싶습니다. –
아이디어가 있습니다. 복잡한 방식으로 이렇게 할 필요는 없습니다. 그러나 내가 알고 싶은 열정과 불안으로부터 : 그것은 데이터 단계에서 가능합니까? 나는 google에서 찾았다. 그러나 내가 여기에 게시했을 정도로 어떤 대답도 찾지 못했다. – Saran