<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Check Data using UPDATE statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-Data-using-UPDATE-statement/m-p/340495#M77822</link>
    <description>&lt;P&gt;To avoid fixing it at 1000 variables (although why you have that amount I don't know) you could just create two arrays and call missing the second:&lt;/P&gt;
&lt;PRE&gt;data test;
  set sashelp.class;
  array vars{*} _numeric_;
  array other{*} _numeric_;
  call missing(of other{*});
run;
&lt;/PRE&gt;
&lt;P&gt;vars{*} contains the data, other{*} is empty, both have same elements.&lt;/P&gt;</description>
    <pubDate>Mon, 13 Mar 2017 17:08:08 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-03-13T17:08:08Z</dc:date>
    <item>
      <title>Check Data using UPDATE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Data-using-UPDATE-statement/m-p/340475#M77812</link>
      <description>&lt;P&gt;Hey All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two quick questions about the best way to do something using the UPDATE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) I have a master dataset that I am trying to update with a transaction dataset. &amp;nbsp;However I want to be able to flag if there are large differences between the value in the master dataset that is being updated with a different value in the transaction dataset. &amp;nbsp; I want to do this to flag things that could be wrong in the transaction dataset and manually check these observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to compare (and maybe output a dataset that includes) the values that are being replaced with the values that are doing the replacing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Same question as above but is there way way to conditionally update a value based on a third value, either in the master or the transaction dataset? &amp;nbsp;Like, update master.a with transaction.a unless master.b gt 10, then don't update.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your help!&lt;/P&gt;
&lt;P&gt;John&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 16:26:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Data-using-UPDATE-statement/m-p/340475#M77812</guid>
      <dc:creator>mahler_ji</dc:creator>
      <dc:date>2017-03-13T16:26:32Z</dc:date>
    </item>
    <item>
      <title>Re: Check Data using UPDATE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Data-using-UPDATE-statement/m-p/340478#M77813</link>
      <description>&lt;P&gt;For your both questions, it would be better if you post some input and desired output,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in order to demostrate your needs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general, for first question - you can rename variables on the transaction dataset&lt;/P&gt;
&lt;P&gt;so that doing update you have the origin and the replacing in differet variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; data new;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; update master(in=inm)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; transactions(in=int &amp;nbsp;rename=(var=var1));&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if int;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var_diff = var1 - var;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 16:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Data-using-UPDATE-statement/m-p/340478#M77813</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-13T16:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: Check Data using UPDATE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Data-using-UPDATE-statement/m-p/340480#M77815</link>
      <description>&lt;P&gt;Thanks for your reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to be able to do this without renaming the variables, since the datasets that I am working with are very large and have hundreds of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 16:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Data-using-UPDATE-statement/m-p/340480#M77815</guid>
      <dc:creator>mahler_ji</dc:creator>
      <dc:date>2017-03-13T16:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: Check Data using UPDATE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Data-using-UPDATE-statement/m-p/340491#M77820</link>
      <description>&lt;P&gt;In general, the answer is that you can't do that.&amp;nbsp; There may be small exceptions, such as being able to use a WHERE clause that affects only the transaction data set.&amp;nbsp; But even that has strict requirements for it to be accurate:&amp;nbsp; one change per transaction observation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The better approach IMO would be to write a program to compare, before applying the transactions.&amp;nbsp; For example (assuming both data sets are sorted by ID):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set master (in=in_master) transactions;&lt;/P&gt;
&lt;P&gt;by ID;&lt;/P&gt;
&lt;P&gt;array nums {*} _numeric_;&lt;/P&gt;
&lt;P&gt;array baseline {1000} _temporary_;&lt;/P&gt;
&lt;P&gt;if first.ID then do _n_=1 to 1000;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; baseline{_n_} = .;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if in_master then do _n_=1 to dim(nums);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; baseline{_n_} = nums{_n_};&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else do _n_=1 to dim(nums);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if baseline{_n_} &amp;gt; . and nums{_n_} &amp;gt; . then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not (0.9 * baseline{_n_} &amp;lt;= nums{_n_} &amp;lt;= 1.1 * baseline {_n_}) then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; master_value = baseline{_n_};&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; trans_value = nums{_n_};&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; varname = vname(nums{_n_});&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;keep id varname master_value trans_value;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This looks for values that are within 10% of the original master value and outputs any out of range.&amp;nbsp; Of course,&amp;nbsp; you can set up your own conditions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1000 is a guess at a maximum number of temporary variables needed.&amp;nbsp; As long as it is greater than or equal to the number of numeric variables in the data set, the program (untested as it is) should be OK.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 16:58:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Data-using-UPDATE-statement/m-p/340491#M77820</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-13T16:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: Check Data using UPDATE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Data-using-UPDATE-statement/m-p/340495#M77822</link>
      <description>&lt;P&gt;To avoid fixing it at 1000 variables (although why you have that amount I don't know) you could just create two arrays and call missing the second:&lt;/P&gt;
&lt;PRE&gt;data test;
  set sashelp.class;
  array vars{*} _numeric_;
  array other{*} _numeric_;
  call missing(of other{*});
run;
&lt;/PRE&gt;
&lt;P&gt;vars{*} contains the data, other{*} is empty, both have same elements.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 17:08:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Data-using-UPDATE-statement/m-p/340495#M77822</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-13T17:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: Check Data using UPDATE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-Data-using-UPDATE-statement/m-p/340548#M77847</link>
      <description>&lt;P&gt;Adapt next code to your needs and environment:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code_ren '/folders/myshortcuts/My_Folders/flat/code_rename.sas';
filename code_dif '/folders/myshortcuts/My_Folders/flat/code_diff.sas';
%let key = name;

data _null_;
  length var $30 new_var $10;
  fid = open('sashelp.class');
  if fid then do;
     nvars = attrn(fid,'nvars'); 
     file log; put nvars=;

     do i=1 to nvars; 
        var = varname(fid,i); 
        if upcase(strip(var)) ne upcase(strip("&amp;amp;key")) then do;
            new_var = 'var_' || left(i);
            _a_line_ = '  rename '||strip(var)||' = '||strip(new_var)||';';
            file code_ren;
            put _a_line_;
            
            file code_dif;
            if vartype(fid,i) = 'N' then do;
               _a_line_ =  'diff_var'||strip(i)||' = '||strip(new_var)||' - '||strip(var)||';';
               put _a_line_ ;
            end; else do;
               _a_line_ = 'diff_var'||strip(i)||' = ('||strip(new_var)||' = '||strip(var)||');';
               put _a_line_ /;
            end;
         end; 
      end;
  end;
  fid = close(fid);
run;
/****/
data check_ren;
  infile code_ren truncover;
  input a_line $80. ;
run;
data check_dif;
  infile code_dif truncover;
  input a_line $80. ;
run;     
/****/

options source2;
data class_trans;
 set sashelp.class;
     %include code_ren;
run;

data class_new;
 update sashelp.class(in=in_master)
        class_trans(in=in_trans);
 by name;
   if in_master;
   %include code_dif;
run;
        
        


    
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Mar 2017 18:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-Data-using-UPDATE-statement/m-p/340548#M77847</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-13T18:49:24Z</dc:date>
    </item>
  </channel>
</rss>

