BookmarkSubscribeRSS Feed

[HASH Object] Hash Object 생성 후 SAS 데이터 세트로 재출력하기

Started ‎06-12-2020 by
Modified ‎06-12-2020 by
Views 111

* Sample 24667: Load a SAS DATA set into a hash object and create a SAS DATA set from a hash object;

 

* 원본 : http://support.sas.com/kb/24/667.html;

 

data a;

  input key a b c;

datalines;

1 10 100 1

1 20 200 2

2 10 100 3

3 10 100 4

4 10 100 5

4 20 200 6

;

 

data _null_;

  /* On the first iteration of the DATA step, create a hash table called H  */

  /* and load it with the values from WORK.A.  Define the KEY and DATA      */

  /* values for H.  Note that by default, key values must be unique in a    */

  /* hash object, so not every record will be loaded into H. (Starting in   */

  /* SAS 9.2, the MULTIDATA: 'YES' argument tag can be used on the DECLARE  */

  /* statement to allow multiple records with the same key value in a hash  */

  /* object.) Also, only those variables defined in DEFINEDATA will be      */

  /* output to WORK.OUT.  Use CALL MISSING to avoid the NOTE in the log that*/

  /* the specified variables were uninitialized.  An assignment statement   */

  /* for these variables would work as well.                                */

  if _n_ = 1 then do;

 

    * h hash object 정의;

    declare hash h(dataset: "work.a");

    * key 값 정의;

    h.definekey('key');

 

    * hash object에 생성되는 data 항목 정의;

    h.definedata('a','b','c');

 

    * 위에서 생성한 데이터를 로딩하여 hash object 생성;

    h.definedone();

    call missing(key,a,b,c);

  end;

 

  /* Use the OUTPUT method to output the records from the hash object H to */

  /* the data set WORK.OUT.                                                */

 

  * SAS 데이터 세트 출력;

  rc = h.output(dataset: "work.out");

run;

 

/* Note, neither KEY nor C will be in WORK.OUT because they were  not */

/* defined in the DEFINEDATA method in the step above.                */

 

* 동이한 key 값 중에서 첫번째 값이 출력된다.(확인을 위하여 원본의 c 변수를 관측치 순서로 변경);

proc print data=work.out;

run;

 

 

***********************************************************
- 통계분석연구회  

- 카페 : http://cafe.daum.net/statsas 

Version history
Last update:
‎06-12-2020 05:11 AM
Updated by:
Contributors

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Article Labels
Article Tags