<?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: Overwriting of a row in a data set by another row in another data set (different values) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229142#M41432</link>
    <description>&lt;P style="margin: 0cm 0cm 8pt;"&gt;&lt;SPAN&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Thank you very much for your support. You have got me right but i couldnt do overwriting on the code you have sent. I think youe code multiplied too. I want it to be 6 rows totally.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0cm 0cm 8pt;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0cm 0cm 8pt;"&gt;&lt;SPAN&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Thanks a lot &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Oct 2015 15:12:15 GMT</pubDate>
    <dc:creator>turcay</dc:creator>
    <dc:date>2015-10-08T15:12:15Z</dc:date>
    <item>
      <title>Overwriting of a row in a data set by another row in another data set (different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229082#M41417</link>
      <description>&lt;P&gt;Assuming that columns with underscore has passed several conditions. I want the rows in the second data set overwrite the one in the first data set. The biggest problem here is that some values don't match because of variable columns (_) in the first and second data set. Another problem is the multiplying rows. I don’t want rows to multiply. The proc sql that i have created below combines the data sets however multiplies the rows. Can you help me about this problem? I have attached the code and the image so it might help you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Main_SQL;
length InstanceID $ 20 Default 8 Q0001_ 8 Q0002_ 8 Q0003 8 Q0004_ 8 Q0005 8 Q0006 8;
infile datalines missover dlm=",";
input InstanceID Default Q0001_ Q0002_ Q0003 Q0004_ Q0005 Q0006 ;
datalines;
InstanceID1,0,0.90,0.80,0.00,0.90,0.00,0.70
InstanceID2,0,0.100,0.100,0.00,0.70,0.00,60
InstanceID3,1,0.40,0.80,0.00,0.90,0.00,0.50
InstanceID4,0,0.55,0.80,0.05,0.90,0.00,0.69
InstanceID5,0,0.00,0.80,0.60,0.90,0.20,0.90
InstanceID6,1,0.96,0.00,0.40,0.90,0.00,0.95
InstanceID7,0,0.00,0.80,0.90,0.90,0.00,0.99
InstanceID8,1,0.56,0.80,0.55,0.90,0.00,0.93
InstanceID9,0,0.99,0.80,0.99,0.90,0.00,0.70
InstanceID10,0,0.89,0.88,0.56,0.90,0.00,0.00
;
run;
Proc means data=Main_SQL STACKODS noprint
FW=12
PRINTALLTYPES
CHARTYPE
QMETHOD=OS
VARDEF=DF
	MEAN
	STD
	MODE
	P10
	P90 ;
VAR Q:;
ODS OUTPUT Summary=backTestGroup2;
run;
data backTestGroup2;
  set backTestGroup2;
  UPPER =((P90-MODE)/(P90-P10))*STDDEV+MODE;
  LOWER =((MODE-P10)/(P90-P10))*STDDEV+MODE;
  CENTER=(UPPER+LOWER)/2;
  SLOPE =2.95/(UPPER-CENTER);
  keep Variable Mean Stddev Center Slope;
run;
data ozMeans;
length Variable $ 12 Mean 8 Stddev 8 Center 8 Slope 8;
infile datalines missover dlm=",";
input Variable Mean Stddev Center Slope;
datalines;
Q0002_,0.700,0.12227662376012,0.56113831188006,-5.3700431505101
Q0004,0.535,0.398281028644069,0.199140514322035,14.8136606458166
Q0006_,0.658,0.32227662376012,0.96113831188006,-20.3700431505101
;
PROC SQL;
Create table backTestGroup2 as
Select* from(Select * from ozMeans 
union all
select * from backTestGroup2
where left(trim(Variable)||"_") not in(Select Variable from ozMeans)) AA
order by aa.variable;
QUIT;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Oct 2015 09:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229082#M41417</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-10-08T09:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Overwriting of a row in a data set by another row in another data set (different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229087#M41418</link>
      <description>&lt;P&gt;Well, I gues that you need to make your Q columns names match somehow. Compressing "_" whould be simple, but perhaps not on your real data?&lt;/P&gt;&lt;P&gt;Then I would use &lt;EM&gt;data step - modify by&lt;/EM&gt; to update the master data set, should not generate duplicates.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2015 09:47:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229087#M41418</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-10-08T09:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: Overwriting of a row in a data set by another row in another data set (different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229092#M41419</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You mean you want to use the values from OZMEANS when they exist or use the other table. &amp;nbsp;If so the below code will do that, the trick is putting the update first in the COALESCE() order, so it will be taken if it exists. &amp;nbsp;Do note, consisten formatting, casing, indetation, makes code far more readable.&lt;/P&gt;
&lt;PRE&gt;data main_sql;
  length instanceid $ 20 default 8 q0001_ 8 q0002_ 8 q0003 8 q0004_ 8 q0005 8 q0006 8;
  infile datalines missover dlm=",";
  input instanceid default q0001_ q0002_ q0003 q0004_ q0005 q0006 ;
datalines;
InstanceID1,0,0.90,0.80,0.00,0.90,0.00,0.70
InstanceID2,0,0.100,0.100,0.00,0.70,0.00,60
InstanceID3,1,0.40,0.80,0.00,0.90,0.00,0.50
InstanceID4,0,0.55,0.80,0.05,0.90,0.00,0.69
InstanceID5,0,0.00,0.80,0.60,0.90,0.20,0.90
InstanceID6,1,0.96,0.00,0.40,0.90,0.00,0.95
InstanceID7,0,0.00,0.80,0.90,0.90,0.00,0.99
InstanceID8,1,0.56,0.80,0.55,0.90,0.00,0.93
InstanceID9,0,0.99,0.80,0.99,0.90,0.00,0.70
InstanceID10,0,0.89,0.88,0.56,0.90,0.00,0.00
;
run;
proc means data=main_sql stackods noprint fw=12 printalltypes chartype qmethod=os vardef=df mean std mode p10 p90;
  var q:;
  ods output summary=backtestgroup2;
run;
data backtestgroup2;
  set backtestgroup2;
  upper =((p90-mode)/(p90-p10))*stddev+mode;
  lower =((mode-p10)/(p90-p10))*stddev+mode;
  center=(upper+lower)/2;
  slope =2.95/(upper-center);
  keep variable mean stddev center slope;
run;
data ozmeans;
  length variable $ 12 mean 8 stddev 8 center 8 slope 8;
  infile datalines missover dlm=",";
  input variable mean stddev center slope;
datalines;
Q0002_,0.700,0.12227662376012,0.56113831188006,-5.3700431505101
Q0004,0.535,0.398281028644069,0.199140514322035,14.8136606458166
Q0006_,0.658,0.32227662376012,0.96113831188006,-20.3700431505101
;
run;

proc sql;
  create table RESULT as
  select  COALESCE(A.VARIABLE,B.VARIABLE) as VARIABLE,
          COALESCE(A.MEAN,B.MEAN) as MEAN,
          COALESCE(A.STDDEV,B.STDDEV) as STDDEV,
          COALESCE(A.CENTER,B.CENTER) as CENTER,
          COALESCE(A.SLOPE,B.SLOPE) as SLOPE
  from    OZMEANS A
  full join BACKTESTGROUP2 B
  on      strip(tranwrd(A.VARIABLE,"_",""))=strip(tranwrd(B.VARIABLE,"_",""));
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Oct 2015 10:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229092#M41419</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-08T10:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: Overwriting of a row in a data set by another row in another data set (different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229142#M41432</link>
      <description>&lt;P style="margin: 0cm 0cm 8pt;"&gt;&lt;SPAN&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Thank you very much for your support. You have got me right but i couldnt do overwriting on the code you have sent. I think youe code multiplied too. I want it to be 6 rows totally.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0cm 0cm 8pt;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0cm 0cm 8pt;"&gt;&lt;SPAN&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Thanks a lot &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2015 15:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229142#M41432</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-10-08T15:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Overwriting of a row in a data set by another row in another data set (different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229149#M41435</link>
      <description>&lt;P&gt;Did you run the code I posted, as when I run it I got 6 records. &amp;nbsp;Post your output if it doesn't work and the code you use.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2015 15:51:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229149#M41435</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-10-08T15:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: Overwriting of a row in a data set by another row in another data set (different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229162#M41442</link>
      <description>&lt;P&gt;Hi RW9,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Am i doing something wrong. The result of table is as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG title="Try.png" alt="Try.png" src="https://communities.sas.com/t5/image/serverpage/image-id/431iBFC3A668C668AA68/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2015 16:58:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229162#M41442</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-10-08T16:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: Overwriting of a row in a data set by another row in another data set (different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229176#M41447</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This should be pretty close to what you are looking for. Note that for "Q0002" and "Q0006", multiple summary statistics are returned, so you will need to&amp;nbsp;use another summary function such as &lt;FONT face="courier new,courier"&gt;MIN()&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;MAX()&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;AVG()&lt;/FONT&gt;. In this example,&amp;nbsp;I used AVG, but you can use MIN or MAX if that better suits your needs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
 /* CREATE TABLE backTestGroup2 AS */
    CREATE TABLE backTestGroup3 AS 
    SELECT Variable  length=20
         , COUNT(DISTINCT CATX('|', Mean, Stddev, Center, Slope, Mean)) AS num_distinct_values
         , AVG(Mean)   AS Mean_Mean
         , AVG(Stddev) AS Mean_Stddev
         , AVG(Center) AS Mean_Center
         , AVG(Slope)  AS Mean_Slope
         , CASE WHEN calculated num_distinct_values &amp;gt; 1 
                THEN '&amp;lt;== Note: summary statistic is an average (more than one unique row was returned)'  
           ELSE '' END AS remark length=100
    FROM (SELECT DISTINCT TRANSTRN(Variable, "_", "") AS Variable, Mean, Stddev, Center, Slope
          FROM ozMeans
          UNION
          SELECT DISTINCT TRANSTRN(Variable, "_", "") AS Variable, Mean, Stddev, Center, Slope
          FROM backTestGroup2
          WHERE TRANSTRN(Variable, "_", "") NOT IN (SELECT Variable FROM ozMeans)) As InnerQry
    GROUP BY Variable
    ORDER BY 1;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the output:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;(edited: updated&amp;nbsp;image; old output was incorrect)&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/435iC88D5D9B289C5693/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="proc_sql_union_mean_of_aggregates_(fixed).gif" title="proc_sql_union_mean_of_aggregates_(fixed).gif" /&gt;&lt;SPAN style="line-height: 20px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;Enjoy.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-- hbi&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2015 19:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229176#M41447</guid>
      <dc:creator>hbi</dc:creator>
      <dc:date>2015-10-08T19:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Overwriting of a row in a data set by another row in another data set (different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229200#M41453</link>
      <description>&lt;P&gt;Thank you very much. But i'm not sure we receive the same results. Because when i run your code i got the data set as below.But your codes give some idea to me to write result which i want it. Thanks a lot&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4218"&gt;@hbi﻿&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/438i91D1DB2AC6F69CDB/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="hbi.png" title="hbi.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your advices seems to be fine. Can you give some sample data set or share with me a link ?&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2015 22:43:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229200#M41453</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-10-08T22:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: Overwriting of a row in a data set by another row in another data set (different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229205#M41455</link>
      <description>&lt;P&gt;If you use "upcase()", your results should be consistent with the one I provided.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;change: &amp;nbsp;&lt;SPAN&gt;TRANSTRN(Variable, "_", "")&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; to: &amp;nbsp;UPCASE(TRANSTRN(Variable, "_", ""))&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;PROC SQL;
 /* CREATE TABLE backTestGroup2 AS */
    CREATE TABLE backTestGroup3 AS 
    SELECT Variable  length=20
         , COUNT(DISTINCT CATX('|', Mean, Stddev, Center, Slope, Mean)) AS num_distinct_values
         , AVG(Mean)   AS Mean_Mean
         , AVG(Stddev) AS Mean_Stddev
         , AVG(Center) AS Mean_Center
         , AVG(Slope)  AS Mean_Slope
         , CASE WHEN calculated num_distinct_values &amp;gt; 1 
                THEN '&amp;lt;== Note: summary statistic is an average (more than one unique row was returned)'  
           ELSE '' END AS remark length=100
    FROM (SELECT DISTINCT &lt;FONT face="arial black,avant garde" color="#FF0000"&gt;UPCASE(TRANSTRN(Variable, "_", ""))&lt;/FONT&gt; AS Variable, Mean, Stddev, Center, Slope
          FROM ozMeans
          UNION
          SELECT DISTINCT &lt;FONT face="arial black,avant garde" color="#FF0000"&gt;UPCASE(TRANSTRN(Variable, "_", ""))&lt;/FONT&gt; AS Variable, Mean, Stddev, Center, Slope
          FROM backTestGroup2
          WHERE &lt;FONT face="arial black,avant garde" color="#FF0000"&gt;UPCASE(TRANSTRN(Variable, "_", "")) &lt;/FONT&gt;
                   NOT IN (SELECT &lt;FONT face="arial black,avant garde" color="#FF0000"&gt;UPCASE(TRANSTRN(Variable, "_", ""))&lt;/FONT&gt; FROM ozMeans)
         ) As InnerQry
    GROUP BY Variable
    ORDER BY 1;
QUIT;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2015 23:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229205#M41455</guid>
      <dc:creator>hbi</dc:creator>
      <dc:date>2015-10-08T23:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: Overwriting of a row in a data set by another row in another data set (different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229486#M41534</link>
      <description>&lt;P&gt;Thanks a lot. It worked.I'll examine whole of the code in detail. Thanks for leaded me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2015 22:11:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overwriting-of-a-row-in-a-data-set-by-another-row-in-another/m-p/229486#M41534</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-10-11T22:11:50Z</dc:date>
    </item>
  </channel>
</rss>

