<?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: how to add a key starting with 2 and merge that file to another in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919654#M362241</link>
    <description>&lt;P&gt;What are the datasets DF1, DF2 and DF3?&amp;nbsp; What do they represent? What are the variables in each of them? Why are you trying to put them together?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show an example of each (preferable with enough observations and variables to demonstrate the issues)..&lt;/P&gt;</description>
    <pubDate>Sat, 09 Mar 2024 17:47:24 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-03-09T17:47:24Z</dc:date>
    <item>
      <title>how to add a key starting with 2 and merge that file to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919643#M362231</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;%macro yatesGunstAnova(dsn,model,class,numBeta,numBeta2);

title 'GLM WITH CONTINUOUS PREDICTORS';
%glmTemplate;
proc glm data=&amp;amp;dsn;
model &amp;amp;model/ ss3 solution;
ods output OverallAnova=OverallAnova;
ods output ModelAnova=ModelAnova; 
ods output ParameterEstimates=ParameterEstimates;
run; quit;

%myprint(ModelAnova); 
data ModelAnova2; set ModelAnova;
%myprint(ModelAnova2); 

data BetaEstimates; set ParameterEstimates; 
keep parameter source estimate RawEffect;
source=compress(parameter,'+'); 
source=compress(source,'*');
source=compress(source,'0');
source=compress(source,'-1');
RawEffect=2*estimate;
run; quit;

%myprint(BetaEstimates);

/* Halfnorm Plot of raw effects */
%halfnorm(BetaEstimates,RawEffect,&amp;amp;numBeta);

/* Standardized DEJ Effects */
data ModelAnova2; set ModelAnova;
source=source;
source=compress(source,'*');
ms=ms;   
StdzEffect=sqrt(ms);
HypothesisType=HypothesisType;
keep source ms StdzEffect HypothesisType;
run; quit;

data df1; set &amp;amp;dsn;
key=_n_;
keep key conv;
run;

data df3; set BetaEstimates;
key=_n_;
run;

proc print data=df1; run; quit;
proc print data=df3; run; quit;

data temp;
/* Generate the key starting from 2 */
do key = 2 to _n_ + 1;
    output;
end;
run;
data df2; merge df2 temp;

/* Read the first dataset */
set df1;
/* Read the second dataset */
set df2;
run;

data df;
merge df df3;
run;

/* Now all three datasets are joined */
proc print data=df;
run; quit;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Mar 2024 16:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919643#M362231</guid>
      <dc:creator>marymarion</dc:creator>
      <dc:date>2024-03-09T16:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a key starting with 2 and merge that file to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919644#M362232</link>
      <description>&lt;P&gt;Most of your code looks illogical, but I think you are particularly asking about this data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Generate the key starting from 2 */
data temp;
  do key = 2 to _n_ + 1;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since _n_ will be initialized to 1 your DO loop as to increment KEY from 2 to 2.&amp;nbsp; So you should get just one observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How many observations do you need?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And more importantly why do you think you need have a dataset with KEY starting from 2 and increasing by 1?&amp;nbsp; What are you going to DO with such a dataset?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Mar 2024 16:22:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919644#M362232</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-09T16:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a key starting with 2 and merge that file to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919646#M362233</link>
      <description>&lt;P&gt;Tom,&lt;/P&gt;&lt;P&gt;I want to combine data, BetaEstimates, and ModelAnova by key. Note ModelAnova has only 15 observations and data and BetaEstimates has 16.&lt;/P&gt;&lt;P&gt;Mary&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Mar 2024 16:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919646#M362233</guid>
      <dc:creator>marymarion</dc:creator>
      <dc:date>2024-03-09T16:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a key starting with 2 and merge that file to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919647#M362234</link>
      <description>&lt;P&gt;i am going to sort it descending and ascending and do a few plots.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Mar 2024 16:56:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919647#M362234</guid>
      <dc:creator>marymarion</dc:creator>
      <dc:date>2024-03-09T16:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a key starting with 2 and merge that file to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919648#M362235</link>
      <description>&lt;P&gt;data is saved as &amp;amp;dsn&lt;/P&gt;</description>
      <pubDate>Sat, 09 Mar 2024 16:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919648#M362235</guid>
      <dc:creator>marymarion</dc:creator>
      <dc:date>2024-03-09T16:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a key starting with 2 and merge that file to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919649#M362236</link>
      <description>&lt;P&gt;When I attempted to add a blank line the software did not like it saying that there will be a mistake later on.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Mar 2024 17:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919649#M362236</guid>
      <dc:creator>marymarion</dc:creator>
      <dc:date>2024-03-09T17:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a key starting with 2 and merge that file to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919650#M362237</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/463997"&gt;@marymarion&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Tom,&lt;/P&gt;
&lt;P&gt;I want to combine data, BetaEstimates, and ModelAnova by key. Note ModelAnova has only 15 observations and data and BetaEstimates has 16.&lt;/P&gt;
&lt;P&gt;Mary&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And what are the key variables that should be used to match the observations?&amp;nbsp; Is it KEY?&amp;nbsp; Then just merge BY KEY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it looks like KEY does not actually exist.&amp;nbsp; In which case what is the variable that should be used?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it actually does make sense to match the observations without any keys then just do that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set BetaEstimates;
  if not eof2 then set ModelAnova end=eof2;
  output;
  call missing(of _all_);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want offset one of them add an additional condition so you skip one of the sets.&amp;nbsp; For example to only start using MODELANOVA on the second observation use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set BetaEstimates;
  if (_n_&amp;gt;1) and not eof2 then set ModelAnova end=eof2;
  output;
  call missing(of _all_);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Mar 2024 17:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919650#M362237</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-09T17:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a key starting with 2 and merge that file to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919651#M362238</link>
      <description>&lt;PRE&gt;%macro yatesGunstAnova(dsn,model,class,numBeta,numBeta2);&lt;BR /&gt;&lt;BR /&gt;title 'GLM WITH CONTINUOUS PREDICTORS';&lt;BR /&gt;%glmTemplate;&lt;BR /&gt;proc glm data=&amp;amp;dsn;&lt;BR /&gt;model &amp;amp;model/ ss3 solution;&lt;BR /&gt;ods output OverallAnova=OverallAnova;&lt;BR /&gt;ods output ModelAnova=ModelAnova; &lt;BR /&gt;ods output ParameterEstimates=ParameterEstimates;&lt;BR /&gt;run; quit;&lt;BR /&gt;&lt;BR /&gt;%myprint(ModelAnova); &lt;BR /&gt;data ModelAnova2; set ModelAnova;&lt;BR /&gt;%myprint(ModelAnova2); &lt;BR /&gt;&lt;BR /&gt;data BetaEstimates; set ParameterEstimates; &lt;BR /&gt;keep parameter source estimate RawEffect;&lt;BR /&gt;source=compress(parameter,'+'); &lt;BR /&gt;source=compress(source,'*');&lt;BR /&gt;source=compress(source,'0');&lt;BR /&gt;source=compress(source,'-1');&lt;BR /&gt;RawEffect=2*estimate;&lt;BR /&gt;run; quit;&lt;BR /&gt;&lt;BR /&gt;%myprint(BetaEstimates);&lt;BR /&gt;&lt;BR /&gt;/* Halfnorm Plot of raw effects */&lt;BR /&gt;%halfnorm(BetaEstimates,RawEffect,&amp;amp;numBeta);&lt;BR /&gt;&lt;BR /&gt;/* Standardized DEJ Effects */&lt;BR /&gt;data ModelAnova2; set ModelAnova;&lt;BR /&gt;source=source;&lt;BR /&gt;source=compress(source,'*');&lt;BR /&gt;ms=ms;   &lt;BR /&gt;StdzEffect=sqrt(ms);&lt;BR /&gt;HypothesisType=HypothesisType;&lt;BR /&gt;keep source ms StdzEffect HypothesisType;&lt;BR /&gt;run; quit;&lt;BR /&gt;&lt;BR /&gt;data df1; set &amp;amp;dsn;&lt;BR /&gt;key=_n_;&lt;BR /&gt;keep key conv;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data df3; set BetaEstimates;&lt;BR /&gt;key=_n_;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc print data=df1; run; quit;&lt;BR /&gt;proc print data=df3; run; quit;&lt;BR /&gt;&lt;BR /&gt;data df2; set ModelAnova2;&lt;BR /&gt;do key = 2 to _n_ + 1; output; end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data df; merge df1 df2; run;&lt;BR /&gt;data df; merge df df3; run;&lt;BR /&gt;&lt;BR /&gt;/* Now all three datasets are joined */&lt;BR /&gt;proc print data=df; run; quit;&lt;BR /&gt;%mend;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Mar 2024 17:19:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919651#M362238</guid>
      <dc:creator>marymarion</dc:creator>
      <dc:date>2024-03-09T17:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a key starting with 2 and merge that file to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919652#M362239</link>
      <description>&lt;P&gt;df2 is now 120 observations long?&amp;nbsp; I don't understand it.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Mar 2024 17:23:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919652#M362239</guid>
      <dc:creator>marymarion</dc:creator>
      <dc:date>2024-03-09T17:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a key starting with 2 and merge that file to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919654#M362241</link>
      <description>&lt;P&gt;What are the datasets DF1, DF2 and DF3?&amp;nbsp; What do they represent? What are the variables in each of them? Why are you trying to put them together?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show an example of each (preferable with enough observations and variables to demonstrate the issues)..&lt;/P&gt;</description>
      <pubDate>Sat, 09 Mar 2024 17:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-add-a-key-starting-with-2-and-merge-that-file-to-another/m-p/919654#M362241</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-09T17:47:24Z</dc:date>
    </item>
  </channel>
</rss>

