<?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: Merge in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956945#M47922</link>
    <description>&lt;P&gt;Make a dataset with _TYPE_ variable set to SCORE.&amp;nbsp; Use the same variable names ( X1 to X9) to hold&amp;nbsp; the coefficients.&amp;nbsp; Add a _NAME_ variable to hold the name you want for the NEW variable with predicted score.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data score;
  retain _name_ 'MyModel' _type_ 'SCORE' ;
  input x1-x9;
cards;
1 2 3 4 5 6 7 8 9
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So this example SCORE dataset is the formula:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;MyModel = X1 +2*X2 +3*X3 +4*x4+5*x5+6*X6+7*X7+8*X8+9*X9;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use PROC SCORE to score your dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc score data=possible_combinations_t score=score out=results;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;First 10 results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1737592813133.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103912i5059299FDBA54544/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1737592813133.png" alt="Tom_0-1737592813133.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jan 2025 00:41:59 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-01-23T00:41:59Z</dc:date>
    <item>
      <title>Merge</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956901#M47918</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Lets say I have a data set with Long structure with all possible combinations of 9 categorical variables.&lt;/P&gt;
&lt;P&gt;Lets say that I have another data set with information of coefficients for each category (for each variable)&lt;/P&gt;
&lt;P&gt;My target- I want to add to data set&amp;nbsp;possible_combinations_t the following columns:&lt;/P&gt;
&lt;P&gt;X1_Coef&lt;/P&gt;
&lt;P&gt;X2_Coef&lt;/P&gt;
&lt;P&gt;X3_Coef&lt;/P&gt;
&lt;P&gt;X4_Coef&lt;/P&gt;
&lt;P&gt;X5_Coef&lt;/P&gt;
&lt;P&gt;X6_Coef&lt;/P&gt;
&lt;P&gt;X7_Coef&lt;/P&gt;
&lt;P&gt;X8_Coef&lt;/P&gt;
&lt;P&gt;X9_Coef&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data possible_combinations_t;
   do x1 = 1 to 3;
   do x2 = 1 to 2;
   do x3 = 1 to 2;
   do x4 = 1 to 3;
   do x5 = 1 to 2;
   do x6 = 1 to 3;
   do x7 = 1 to 4;
   do x8 = 1 to 2;
   do x9 = 1 to 3;
     output;
  end;
  end;
  end;
  end;
  end;
  end;
  end;
  end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 18:40:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956901#M47918</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-01-22T18:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: Merge</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956902#M47919</link>
      <description>&lt;P&gt;I don't think you provided enough information to answer the question.&lt;/P&gt;
&lt;P&gt;If you want to merge two datasets we need to see what the datasets look like.&amp;nbsp; Do they have a common variable that be used in a BY statement?&amp;nbsp; If not you might need to use PROC SQL so you can craft logic to find the matching observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your use of the term COEFFIENT makes it sound like perhaps you want score data using a formula?&amp;nbsp; Did you look into using PROC SCORE?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2025 18:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956902#M47919</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-22T18:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Merge</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956945#M47922</link>
      <description>&lt;P&gt;Make a dataset with _TYPE_ variable set to SCORE.&amp;nbsp; Use the same variable names ( X1 to X9) to hold&amp;nbsp; the coefficients.&amp;nbsp; Add a _NAME_ variable to hold the name you want for the NEW variable with predicted score.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data score;
  retain _name_ 'MyModel' _type_ 'SCORE' ;
  input x1-x9;
cards;
1 2 3 4 5 6 7 8 9
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So this example SCORE dataset is the formula:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;MyModel = X1 +2*X2 +3*X3 +4*x4+5*x5+6*X6+7*X7+8*X8+9*X9;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use PROC SCORE to score your dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc score data=possible_combinations_t score=score out=results;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;First 10 results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1737592813133.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103912i5059299FDBA54544/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1737592813133.png" alt="Tom_0-1737592813133.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 00:41:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956945#M47922</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-23T00:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Merge</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956959#M47924</link>
      <description>&lt;P&gt;Sorry&lt;/P&gt;
&lt;P&gt;Here are 2&amp;nbsp; data sets I want to merge&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data possible_combinations_t;
   do x1 = 1 to 3;
   do x2 = 1 to 2;
   do x3 = 1 to 2;
   do x4 = 1 to 3;
   do x5 = 1 to 2;
   do x6 = 1 to 3;
   do x7 = 1 to 4;
   do x8 = 1 to 2;
   do x9 = 1 to 3;
     output;
  end;
  end;
  end;
  end;
  end;
  end;
  end;
  end;
  end;
run;

Data coef_t;
input var $  value coefficient;
cards;
X1 1	 -0.1
X1 2	 0.25
X1 3 	0
X2 1	 0.35
X2 2	 0
X3 1	 0.75
X3 2	 0
X4 1	 0.95
X4 2	 1.45
X4 3 	0
X5 1	 -1.2
X5 2	 0
X6 1	 -1.1
X6 2	 2.2
X6 3	 0
X7 1	 -0.7
X7 2	 0.8
X7 3	 1.6
X7 4 	0
X8 1	 -1.1
X8 2  0
X9 1	 0.6
X9 2	 0.9
X9 3 	0
INTER 1 -2.5
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jan 2025 07:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956959#M47924</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-01-23T07:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: Merge</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956960#M47925</link>
      <description>&lt;P&gt;Can&amp;nbsp; you please show how score data set is looking like?&lt;/P&gt;
&lt;P&gt;Does it have only one row??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 07:57:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956960#M47925</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-01-23T07:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: Merge</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956961#M47926</link>
      <description>&lt;P&gt;Sorry I dont understand&lt;/P&gt;
&lt;P&gt;You created a data set called score with columns X1-X9 (see input statement)&lt;/P&gt;
&lt;P&gt;then you used retain statement and wrote there columns _name_ myModel _type_ score.&lt;/P&gt;
&lt;P&gt;I dont see these columns in your daat set&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;data score;
  retain _name_ 'MyModel' _type_ 'SCORE' ;
  input x1-x9;
cards;
1 2 3 4 5 6 7 8 9
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 08:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956961#M47926</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-01-23T08:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Merge</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956962#M47927</link>
      <description>&lt;P&gt;You are on this forum for so long that you could at least to try provide some "my own experiments" solutions in your questions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data possible_combinations_t;
   do x1 = 1 to 3;
   do x2 = 1 to 2;
   do x3 = 1 to 2;
   do x4 = 1 to 3;
   do x5 = 1 to 2;
   do x6 = 1 to 3;
   do x7 = 1 to 4;
   do x8 = 1 to 2;
   do x9 = 1 to 3;
     output;
  end;
  end;
  end;
  end;
  end;
  end;
  end;
  end;
  end;
run;

Data coef_t;
input var $  value coefficient;
cards;
X1 1	 -0.1
X1 2	 0.25
X1 3 	0
X2 1	 0.35
X2 2	 0
X3 1	 0.75
X3 2	 0
X4 1	 0.95
X4 2	 1.45
X4 3 	0
X5 1	 -1.2
X5 2	 0
X6 1	 -1.1
X6 2	 2.2
X6 3	 0
X7 1	 -0.7
X7 2	 0.8
X7 3	 1.6
X7 4 	0
X8 1	 -1.1
X8 2  0
X9 1	 0.6
X9 2	 0.9
X9 3 	0
INTER 1 -2.5
;
Run;

data want;
  if 1=_N_ then
    do;
      if 0 then set coef_t;
      declare hash H(dataset:"coef_t");
      H.defineKey("var", "value");
      H.defineData("coefficient");
      H.defineDone();
      drop i var value coefficient;
    end;

  set possible_combinations_t;

  /* X1_Coef ... x9_Coef  - stupid SAS manes, 
  that's why I'm caling them XCoef_1 = XCoef_9 
  */
  array XCoef_[9];
  array x[9];

  do i = 1 to dim(x);
    if 0=H.find(key: strip(upcase(vname(x[i]))), key:x[i]) 
      then XCoef_[i] = coefficient; 
  end;

  /* INTER=-2.5; */ /* &amp;lt;-- uncomment if you need INTER */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 09:08:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956962#M47927</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-01-23T09:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: Merge</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956989#M47928</link>
      <description>&lt;P&gt;Not clear where you are going with this, but to combine those two datasets I would convert the first one into a "tall" dataset so it has VAR and VALUE variables like the second one does.&amp;nbsp; Might help to remember which observations the values came from.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tall;
  row+1;
  set possible_combinations_t ;
  length var $8 value 8;
  array x[9] ;
  do index=1 to dim(x);
     var=upcase(vname(x[index]));
     value=x[index];
     output;
  end;
  drop x: ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can sort and merge by VAR and VALUE.&amp;nbsp; Or let PROC SQL do it for you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table want as 
select * 
from tall natural join coef_t
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1737647145828.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103921iEE500F1CCA267D94/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1737647145828.png" alt="Tom_0-1737647145828.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 15:45:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956989#M47928</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-23T15:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: Merge</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956990#M47929</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sorry I dont understand&lt;/P&gt;
&lt;P&gt;You created a data set called score with columns X1-X9 (see input statement)&lt;/P&gt;
&lt;P&gt;then you used retain statement and wrote there columns _name_ myModel _type_ score.&lt;/P&gt;
&lt;P&gt;I dont see these columns in your daat set&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;data score;
  retain _name_ 'MyModel' _type_ 'SCORE' ;
  input x1-x9;
cards;
1 2 3 4 5 6 7 8 9
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did you trying running PROC PRINT on the SCORE dataset?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jan 2025 15:46:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Merge/m-p/956990#M47929</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-23T15:46:23Z</dc:date>
    </item>
  </channel>
</rss>

