LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 2006, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 13 Nov 2006 12:13:37 -0500
Reply-To:   "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Subject:   Re: Modify Statement

On Mon, 13 Nov 2006 03:16:33 -0800, Jakl <freiraum@GMAIL.COM> wrote:

>Hi all, > >I'm trying to implement a simple mechanism to update a master-dataset >according to another dataset containing change-records. > >Master (4 variables -> a,b,c,d / one record): > >a | b | c | d | >------------------ >1 | 2 | 3 | 4 | > >Change_DS (4 variables -> a,b,c,d / one record): > >a | b | c | d | >------------------ >1 | 2 | 3 | 5 | > >An index is created on both datasets: > >proc datasets lib = testlib nolist; > modify Master; > index create a; >quit; > >Same goes for Change_DS. > >The following code, taken from >http://support.sas.com/onlinedoc/913/getDoc/de/lrcon.hlp/a001104667.htm >, simply does not update Master. The record in Master is still 1 | 2 | >3 | 4 , whereas d=4 should be d=5 according to Change_DS. > > >data testlib.Master; > set testlib.Change_DS; > modify testlib.Master key = a / unique; > > select (_iorc_); > when(%sysrc(_sok)) do; > put "Entered _sok"; > replace testlib.Master; > *replace; > end; > when(%sysrc(_dsenom)) do; > put "Entered _dsenom"; > output; > _error_ = 0; > end; > otherwise do; > put 'ERROR: Unexpected value for _IORC_= ' _iorc_; > put 'Program terminating. Data step iteration # ' _n_; > put _all_; > _error_ = 0; > stop; > end; > end; >run; > > > >Wheres my mistake? This seems so simple, like when I change the >"replace" statement to "remove", the record gets correctly removed from >Master. But replace.. just doesn't replace. > >Any help is greatly appreciated. Thanks in advance. > >Regards, >Jakl

As long as the keys are unique in the master file, things will be simpler if you use BY processing.

Here's an example:

data class5; set sashelp.class(obs=5); run;

CLASS5 looks like this:

Name Sex Age Height Weight

Alfred M 14 69.0 112.5 Alice F 13 56.5 84.0 Barbara F 13 65.3 98.0 Carol F 14 62.8 102.5 Henry M 14 63.5 102.5

Here's the transactions data set:

data rev; input name $ age height; cards; Henry . 67 Alice 14 59 ;

To apply the revisions:

data class5; modify class5 rev; by name; run;

End result:

Name Sex Age Height Weight

Alfred M 14 69.0 112.5 Alice F 14 59.0 84.0 Barbara F 13 65.3 98.0 Carol F 14 62.8 102.5 Henry M 14 67.0 102.5

No index or sort order necessary for either data set, though an index on the master data set is advisable for the sake of performance.


Back to: Top of message | Previous page | Main SAS-L page