1 / 10

Sugif 12.3.2014 by Heikki Herva

Sugif 12.3.2014 by Heikki Herva. HASH-Objekti ”Taulukkotietorakenne”. /************************************** * Yhdistely perinteisellä Mergellä. * **************************************/ * Ensiksi lajitellaan ensimmäinen taulu; proc sort data =asiakas_perustiedot

tabib
Télécharger la présentation

Sugif 12.3.2014 by Heikki Herva

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sugif 12.3.2014by Heikki Herva HASH-Objekti ”Taulukkotietorakenne”

  2. /**************************************\ * Yhdistely perinteisellä Mergellä. * \**************************************/ * Ensiksi lajitellaan ensimmäinen taulu; procsortdata=asiakas_perustiedot out=asiakas_perustiedot_s; by pankki astun; run; NOTE: There were nobservations read from the data set ASIAKAS_PERUSTIEDOT. NOTE: The data set ASIAKAS_PERUSTIEDOT_S has nobservations and nvariables. NOTE: PROCEDURE SORT used (Total process time): real time 2:52.24 cpu time 1:43.17 * Toiseksi lajitellaan toinen taulu; procsortdata=asiakaskokonaisuudet out=asiakaskokonaisuudet_s; by pankki astun; run; NOTE: There were nobservations read from the data set ASIAKASKOKONAISUUDET. WHERE tyyppi_kd='R'; NOTE: The data set ASIAKASKOKONAISUUDET _S has nobservations and nvariables. NOTE: PROCEDURE SORT used (Total process time): real time 1.33 seconds cpu time 0.57 seconds

  3. * Sitten Merge; data asiakas_ja_osallisuus_mergella; merge asiakas_perustiedot_s (in=ap) asiakaskokonaisuudet_s (in=ao); by pankki astun; ifap; run; NOTE: There were nobservations read from the data set ASIAKAS_PERUSTIEDOT_S. NOTE: There were nobservations read from the data set ASIAKASKOKONAISUUDET_S. NOTE: The data set WORK.ASIAKAS_JA_OSALLISUUS_MERGELLA has nobservations and nvariables. NOTE: DATA statement used (Total process time): real time 2:23.97 cpu time 1:11.52

  4. /**************************************\ * Yhdistely Hash-objektin avulla. * \**************************************/ * Lajittelua ei tarvita; dataasiakas_ja_osallisuus_hashilla; if _n_ eq 1thendo; declare hash demohash(dataset:'asiakaskokonaisuudet'); demohash.defineKey('pankki','astun'); demohash.defineDone(); end; setasiakas_perustiedot; ifdemohash.find() in (0, 160038) thenoutput; run; NOTE: There were nobservations read from the data set ASIAKASKOKONAISUUDET_S. NOTE: There were nobservations read from the data set ASIAKAS_PERUSTIEDOT. NOTE: The data set WORK.ASIAKAS_JA_OSALLISUUS_HASHILLA has nobservations and nvariables. NOTE: DATA statement used (Total process time): real time 2:41.20 cpu time 1:09.68

  5. datademolibr.hyvaksytyt_sopimukset demolibr.alle_12_konttorissa demolibr.ei_maksuja_konttorissa; mergedemolibr.liikevaihto_12kk (in=lv) demolibr.sopimus_tapahtumat (in=st) ; by pankki astun; attribsarake_55_rm format= commax17.2length= 8; attrib sarake_60_rm format = commax17.2length = 8; if (_n_ eq 1) thendo; * Luodaan hash-taulu konttorissa tehdyistä maksuista.; declare hash hmaksut(dataset: ”nimi_muutettu_sum"); hmaksut.defineKey("pankki","astun"); hmaksut.defineData("pankki","astun","kappalemaara","rahamaara"); hmaksut.defineDone();

  6. * Luodaan hash-taulu omista varoista.; declare hash omatvara(ordered:"a"); omatvara.defineKey("oytun","oyvol_luokitt1"); omatvara.defineData("oytun","oyvol_luokitt1", "oyvol_tietotyyppi","oyvol_rahamaara"); omatvara.defineDone(); dountil (eof_toy_vol); setdemolibr.toy_volyymit (keep=oytun oyvol_luokitt1 oyvol_tietotyyppi oyvol_rahamaara) end=eof_toy_vol; if oyvol_tietotyyppi = 'CA' and oyvol_luokitt1 in('40','01') and substr(oytun,7,4) eq '9000'thendo; omatvara.add(); end; end; end;

  7. pankki = substr(pankki,1,6); astun = astun; rc = hmaksut.find(); select (rc); when (0) do; /* Asiakkaalle löytyi maksutoimeksiantoja. */ if kappalemaara ge 12thendo; /* Haetaan hash-taulusta pankkien omat varat. */ oytun = cats(pankki, '9000'); oyvol_luokitt1 = '40'; rc = omatvara.find(); select (rc); when (0) do; /* Haku onnistui. */ sarake_55_rm = oyvol_rahamaara; end; when (160038) do; /* Pankille ei löytynyt omia varoja. Luokittelu 40. */ sarake_55_rm = .; end; otherwise do; put'VIRHE: Pankin omien varojen haku hash-taulusta epäonnistui. Luokittelukoodi 40. ' pankki= rc= ’.’; put'VIRHE: Ajo kaadetaan.'; abort; end; end;

  8. oyvol_luokitt1 = '01'; rc = omatvara.find(); select (rc); when (0) do; /* Haku onnistui. */ sarake_60_rm = oyvol_rahamaara; end; when (160038) do; /* Pankille ei löytynyt omia varoja. Luokittelu 01. */ sarake_60_rm = .; end; otherwise do; put'VIRHE: Pankin omien varojen haku hash-taulusta epäonnistui. Luokittelukoodi 01. ' pankki= rc=; put'VIRHE: Ajo kaadetaan.'; abort; end; end; end; elsedo; outputdemolibr.alle_12_konttorissa; end; end;

  9. when(160038) do; • /* Asiakkaalle ei löytynyt maksutoimeksiantoja. */ • outputdemolibr.ei_maksuja_konttorissa; • end; • otherwise do; • /* Ilmeisesti joku todellinen ongelma. Tehdään virhe. */ • put'VIRHE: Haku maksuliikkeen hash-taulusta epäonnistui. ' rc= '.'; • abort; • end; • end; • run;

  10. Muutamia muita hash-metodeja Replace() - Päivittää avaimen perusteella rivin hash-objektissa. Check() - Onko avaimella riviä hash-objektissa. Ei muuta datan arvoa. Remove() - Poistaa rivin hash-objektista. Output() - Kirjoittaa hash-objektin SAS-tauluksi. Ref() - Tekee haun, Find(), ja jos avaimella ei löydy riviä hash-objektista, lisää rivin hash-objektiin. First(), Last(), Next(), Prev() - Luetaan hash-objektia peräkkäisjärjestyksessä läpi, eteenpäin tai taaksepäin. Hash-metodien referenssikortin saa googlettamalla sas9 hash object tip sheet.

More Related