{"id":3463,"date":"2021-07-06T22:30:42","date_gmt":"2021-07-06T20:30:42","guid":{"rendered":"http:\/\/van-maanen.com\/?p=3463"},"modified":"2021-07-06T22:30:42","modified_gmt":"2021-07-06T20:30:42","slug":"sas-error-but-correct-outcomes","status":"publish","type":"post","link":"http:\/\/archief.van-maanen.com\/?p=3463","title":{"rendered":"SAS, error but correct outcomes"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Recently I noticed that an error in SAS does not automatically lead to wroung outcomes. Look what happens.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I created two tables that are sorted by a field (nummer). <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">proc import datafile = 'C:\\Users\\tomva\\SynologyDrive\\SAS\\input.xlsx'<br>dbms=xlsx out=input replace;<br>run;<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">proc means data=input sum noprint;<br>by nummer;<br>var aantal;<br>output out=sumtot sum=;<br>run;<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">data sumtot(drop=_<em>type<\/em>_ _<em>freq<\/em>_);\nset sumtot(rename=(aantal=sum_aantal));\nrun;<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">proc sort data=sumtot;by nummer;run;<br>proc sort data=input;by nummer;run;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I then decided to join the tables on [nummer], the very field that is used to sort the records upon.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I did this in two steps.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">proc datasets library=work noprint;<br>modify sumtot;<br>index create nummer;<br>run;<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">data som;<br>set input;<br>set sumtot key=nummer;<br>aandeel = aantal\/sum_aantal;<br>run;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The output looked as I expected. But then I saw in the logfile something strange: a warning saying that several records were not matched due to absence of data:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">nummer=1 aantal=15 teller=2 sum_aantal=25 aandeel=0.6 <em>ERROR<\/em>=1 <em>IORC<\/em>=1230015 <em>N<\/em>=2<br>nummer=2 aantal=13 teller=4 sum_aantal=43 aandeel=0.3023255814 <em>ERROR<\/em>=1 <em>IORC<\/em>=1230015 <em>N<\/em>=4<br>nummer=2 aantal=18 teller=5 sum_aantal=43 aandeel=0.4186046512 <em>ERROR<\/em>=1 <em>IORC<\/em>=1230015 <em>N<\/em>=5<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This can be explained by the fact that we have an n to 1 join, whereby in the first match a record from the n side is read along with a record from the 1 side. In the next round, another record from the n-side is read but no other record in the 1 side is found that matches the record. Therefore the old values are retained and subsequently written as the run statement is encountered.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I noticed that an error in SAS does not automatically lead to wroung outcomes. Look what happens. I created two tables that are sorted by a field (nummer). proc import datafile = &#8216;C:\\Users\\tomva\\SynologyDrive\\SAS\\input.xlsx&#8217;dbms=xlsx out=input replace;run; proc means data=input sum noprint;by nummer;var aantal;output out=sumtot sum=;run; data sumtot(drop=_type_ _freq_); set sumtot(rename=(aantal=sum_aantal)); run; proc sort data=sumtot;by nummer;run;proc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-3463","post","type-post","status-publish","format-standard","hentry","category-allgemein"],"_links":{"self":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3463"}],"version-history":[{"count":0,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/3463\/revisions"}],"wp:attachment":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3463"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}