<?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: dataset collation in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/dataset-collation/m-p/851815#M82385</link>
    <description>&lt;P&gt;Below one way to get there.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input year agep N;
 datalines;
2000 3 4
2000 5 6
2000 6 7
;

data classdata;
  year=2000;
  n=0;
  do agep=1 to 6;
    output;
  end;
run;

data want;
  merge classdata have;
  by year agep;
run;

proc print data=want;
  var year agep n;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1672659101376.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78975iCF699FECDD0806E4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1672659101376.png" alt="Patrick_0-1672659101376.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;With a merge "last wins": If there is a matching row from table have (listed last in the merge statement) then the value for agep will be taken from that table (=overwriting the value from classdata). If there is no matching row then agep will have the value from classdata.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 02 Jan 2023 11:36:08 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2023-01-02T11:36:08Z</dc:date>
    <item>
      <title>dataset collation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dataset-collation/m-p/851809#M82382</link>
      <description>&lt;P&gt;Hi, I am a beginner in SAS&lt;/P&gt;&lt;P&gt;I have a dataset like below&lt;BR /&gt;&lt;BR /&gt;year&amp;nbsp; &amp;nbsp; &amp;nbsp; agep&amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;2000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;2000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/P&gt;&lt;P&gt;2000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are 6 age groups in my dataset. I would like to know if I can via SAS code finish the below table automatically.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;year&amp;nbsp; &amp;nbsp; &amp;nbsp; agep&amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;2000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;2000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/P&gt;&lt;P&gt;2000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2023 11:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dataset-collation/m-p/851809#M82382</guid>
      <dc:creator>pfvk</dc:creator>
      <dc:date>2023-01-02T11:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: dataset collation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dataset-collation/m-p/851810#M82383</link>
      <description>&lt;P&gt;Is this your actual data or sample data that resembles your actual data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the agep variable always values from 1 to 6 or can it vary?&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2023 11:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dataset-collation/m-p/851810#M82383</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2023-01-02T11:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: dataset collation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dataset-collation/m-p/851811#M82384</link>
      <description>&lt;P&gt;How would the programmer (in this case you or me) know that the values of N start at zero and continue up to 6 (and not go above 6)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want code that works on this exact data set, or is the problem more general and has to work on similar data sets with different values of N?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to create a table or report? Or are you trying to create a data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2023 11:18:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dataset-collation/m-p/851811#M82384</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-02T11:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: dataset collation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dataset-collation/m-p/851815#M82385</link>
      <description>&lt;P&gt;Below one way to get there.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input year agep N;
 datalines;
2000 3 4
2000 5 6
2000 6 7
;

data classdata;
  year=2000;
  n=0;
  do agep=1 to 6;
    output;
  end;
run;

data want;
  merge classdata have;
  by year agep;
run;

proc print data=want;
  var year agep n;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1672659101376.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78975iCF699FECDD0806E4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1672659101376.png" alt="Patrick_0-1672659101376.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;With a merge "last wins": If there is a matching row from table have (listed last in the merge statement) then the value for agep will be taken from that table (=overwriting the value from classdata). If there is no matching row then agep will have the value from classdata.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2023 11:36:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dataset-collation/m-p/851815#M82385</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-01-02T11:36:08Z</dc:date>
    </item>
  </channel>
</rss>

