<?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: Q1: match/merge files adding variables not records/rows, Q2: accessing record counter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Q1-match-merge-files-adding-variables-not-records-rows-Q2/m-p/777722#M247471</link>
    <description>On Q1. I thought of merge and tried it.&lt;BR /&gt;data stack4; merge stacky3 cohorts2; by ybw; run;&lt;BR /&gt;&lt;BR /&gt;NOTE: There were 9145 observations read from the data set WORK.STACKY3.&lt;BR /&gt;NOTE: There were 36 observations read from the data set WORK.COHORTS2.&lt;BR /&gt;NOTE: The data set WORK.STACK4 has 9163 observations and 753 variables.&lt;BR /&gt;&lt;BR /&gt;Continuing with my example&lt;BR /&gt;File a&lt;BR /&gt;1 2 3 4 5&lt;BR /&gt;1 8 4 5 9&lt;BR /&gt;1 9 3 4 5&lt;BR /&gt;2 8 3 1 1&lt;BR /&gt;2 9 3 4 5&lt;BR /&gt;&lt;BR /&gt;File b&lt;BR /&gt;1 99&lt;BR /&gt;2 56&lt;BR /&gt;&lt;BR /&gt;What I got&lt;BR /&gt;1 2 3 4 5 99&lt;BR /&gt;1 8 4 5 9 99&lt;BR /&gt;1 9 3 4 5 99&lt;BR /&gt;2 8 3 1 1 56&lt;BR /&gt;2 9 3 4 5 56&lt;BR /&gt;. . . . . 99&lt;BR /&gt;. . . . . 56&lt;BR /&gt;&lt;BR /&gt;I ran your example and it works as I expected it to, i.e., correctly.&lt;BR /&gt;My result suggests a blank record in the stacky3 dataset; however, looking frequencies on a variable there is no missing data. Thus, I assume no blank record. I also checked frequencies in both files on my by variable and no missing data there either. According to the notes everything worked perfectly except it didn't. Suggestions about how to debug the problem? Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;On Q2. Thanks. So, then I could say something like this?&lt;BR /&gt;if (_n_ ge 34 and _n_ le 44) then&lt;BR /&gt;put something somewhere (skip over the put part; I'm concerned about the if part)&lt;BR /&gt;</description>
    <pubDate>Mon, 01 Nov 2021 16:53:48 GMT</pubDate>
    <dc:creator>emaguin</dc:creator>
    <dc:date>2021-11-01T16:53:48Z</dc:date>
    <item>
      <title>Q1: match/merge files adding variables not records/rows, Q2: accessing record counter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Q1-match-merge-files-adding-variables-not-records-rows-Q2/m-p/777667#M247444</link>
      <description>&lt;P&gt;Q1: How in sas do i do what would be in spss a match files with a table? so, suppose&lt;/P&gt;&lt;P&gt;File A with variables id w e r t&lt;BR /&gt;1 2 3 4 5&lt;BR /&gt;1 8 4 5 9&lt;BR /&gt;1 9 3 4 5&lt;BR /&gt;2 8 3 1 1&lt;BR /&gt;2 9 3 4 5&lt;/P&gt;&lt;P&gt;file B with variables id kk&lt;BR /&gt;1 99&lt;BR /&gt;2 56&lt;/P&gt;&lt;P&gt;to get id w e r t kk&lt;BR /&gt;1 2 3 4 5 99&lt;BR /&gt;1 8 4 5 9 99&lt;BR /&gt;1 9 3 4 5 99&lt;BR /&gt;2 8 3 1 1 56&lt;BR /&gt;2 9 3 4 5 56&lt;/P&gt;&lt;P&gt;in spss&lt;BR /&gt;match file file=a/table=b/by id.&lt;/P&gt;&lt;P&gt;in sas?????&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Q2: What is the sas record counter variable? In spss it is $casenum. What is it in sas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 01 Nov 2021 13:09:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Q1-match-merge-files-adding-variables-not-records-rows-Q2/m-p/777667#M247444</guid>
      <dc:creator>emaguin</dc:creator>
      <dc:date>2021-11-01T13:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: Q1: match/merge files adding variables not records/rows, Q2: accessing record counter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Q1-match-merge-files-adding-variables-not-records-rows-Q2/m-p/777668#M247445</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input id w e r t;
datalines;
1 2 3 4 5
1 8 4 5 9
1 9 3 4 5
2 8 3 1 1
2 9 3 4 5
;

data b;
input id kk;
datalines;
1 99
2 56
;

data want;
   merge a b;
   by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Nov 2021 13:16:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Q1-match-merge-files-adding-variables-not-records-rows-Q2/m-p/777668#M247445</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-11-01T13:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: Q1: match/merge files adding variables not records/rows, Q2: accessing record counter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Q1-match-merge-files-adding-variables-not-records-rows-Q2/m-p/777675#M247449</link>
      <description>&lt;P&gt;The number of observations in a dataset can be retrieved from DICTIONARY.TABLES (SQL) or SASHELP.VTABLE (data or other procedure steps).&lt;/P&gt;
&lt;P&gt;In a data step, you can use the NOBS= option in a SET statement to define a variable that holds this number.&lt;/P&gt;
&lt;P&gt;If you use a simple data step (which only reads one observation per iteration) you can use _N_ to retrieve the number of the &lt;EM&gt;current&lt;/EM&gt; observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the match/merge, use either the data step MERGE as shown by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;, or use SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select a.*, b.kk
  from a left join b
  on a.id = b.id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Nov 2021 13:26:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Q1-match-merge-files-adding-variables-not-records-rows-Q2/m-p/777675#M247449</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-01T13:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: Q1: match/merge files adding variables not records/rows, Q2: accessing record counter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Q1-match-merge-files-adding-variables-not-records-rows-Q2/m-p/777722#M247471</link>
      <description>On Q1. I thought of merge and tried it.&lt;BR /&gt;data stack4; merge stacky3 cohorts2; by ybw; run;&lt;BR /&gt;&lt;BR /&gt;NOTE: There were 9145 observations read from the data set WORK.STACKY3.&lt;BR /&gt;NOTE: There were 36 observations read from the data set WORK.COHORTS2.&lt;BR /&gt;NOTE: The data set WORK.STACK4 has 9163 observations and 753 variables.&lt;BR /&gt;&lt;BR /&gt;Continuing with my example&lt;BR /&gt;File a&lt;BR /&gt;1 2 3 4 5&lt;BR /&gt;1 8 4 5 9&lt;BR /&gt;1 9 3 4 5&lt;BR /&gt;2 8 3 1 1&lt;BR /&gt;2 9 3 4 5&lt;BR /&gt;&lt;BR /&gt;File b&lt;BR /&gt;1 99&lt;BR /&gt;2 56&lt;BR /&gt;&lt;BR /&gt;What I got&lt;BR /&gt;1 2 3 4 5 99&lt;BR /&gt;1 8 4 5 9 99&lt;BR /&gt;1 9 3 4 5 99&lt;BR /&gt;2 8 3 1 1 56&lt;BR /&gt;2 9 3 4 5 56&lt;BR /&gt;. . . . . 99&lt;BR /&gt;. . . . . 56&lt;BR /&gt;&lt;BR /&gt;I ran your example and it works as I expected it to, i.e., correctly.&lt;BR /&gt;My result suggests a blank record in the stacky3 dataset; however, looking frequencies on a variable there is no missing data. Thus, I assume no blank record. I also checked frequencies in both files on my by variable and no missing data there either. According to the notes everything worked perfectly except it didn't. Suggestions about how to debug the problem? Thanks.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;On Q2. Thanks. So, then I could say something like this?&lt;BR /&gt;if (_n_ ge 34 and _n_ le 44) then&lt;BR /&gt;put something somewhere (skip over the put part; I'm concerned about the if part)&lt;BR /&gt;</description>
      <pubDate>Mon, 01 Nov 2021 16:53:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Q1-match-merge-files-adding-variables-not-records-rows-Q2/m-p/777722#M247471</guid>
      <dc:creator>emaguin</dc:creator>
      <dc:date>2021-11-01T16:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: Q1: match/merge files adding variables not records/rows, Q2: accessing record counter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Q1-match-merge-files-adding-variables-not-records-rows-Q2/m-p/777734#M247477</link>
      <description>&lt;P&gt;When you MERGE the observations with the same values of the BY variables are combined. (If one or more of the datasets have multiple observations for the same set of BY variable values then the observations are matched in order and any dataset that runs out of observations for that group will just keep the values the last observation in the group had).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in your example:&lt;/P&gt;
&lt;PRE&gt;NOTE: There were 9145 observations read from the data set WORK.STACKY3.
NOTE: There were 36 observations read from the data set WORK.COHORTS2.
NOTE: The data set WORK.STACK4 has 9163 observations and 753 variables.
&lt;/PRE&gt;
&lt;P&gt;If none of the YBW values matched then the number of observations written would be the sum of the number read from each input.&amp;nbsp; Since 9,163 is less than 9,145 plus 36 there are some value of YBW that did match.&amp;nbsp; &amp;nbsp;Since 9,163 is more than 9,145 there are some observations where the value of YBM did not match (or where that value appeared more than once in WORK.COHORTS2)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To find out exactly which they are you can use the IN= dataset options on the input datasets to create temporary variables that will be true when that dataset is contributing data.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Nov 2021 17:52:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Q1-match-merge-files-adding-variables-not-records-rows-Q2/m-p/777734#M247477</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-01T17:52:02Z</dc:date>
    </item>
  </channel>
</rss>

