<?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 assign same number by group with no prime key? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834654#M35898</link>
    <description>&lt;P&gt;Your INPUT statement does not match the number of variables in the data lines.&lt;/P&gt;
&lt;P&gt;Your BY statement does not match the variables in your dataset.&lt;/P&gt;
&lt;P&gt;You are attempting to use a FIRST.xxx variable that does not exist since it was not included in the BY statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like your KEY consists of some, but not all , of the variables.&amp;nbsp; In particular the first "date" and the last "num" are not part of the key.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date1 kind date2 date3 date4 code1 $ code2 num1 num2 tmp_no;
cards;
201501 1 20000930 20210722 19600702 N 1 60 2000 1
201502 1 20000930 20210722 19600702 N 1 60 3000 1
201501 3 20011231 20211002 19990821 Y 2 61 3000 2
201507 5 20040308 99991231 19661230 Y 2 77 5000 3
201508 5 20040308 99991231 19661230 Y 2 77 5000 3
201512 1 20020125 99991231 19990821 Y 1 130 2000 4
;

proc sort ;
  by kind date2 date3 date4 code1 code2 num1 ;
run;

data want;
  set have;
  by kind date2 date3 date4 code1 code2 num1;
  new_num + first.num1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs     date1    kind      date2       date3       date4     code1    code2    num1    num2    tmp_no    new_num

 1     201501      1     20000930    20210722    19600702      N        1        60    2000       1         1
 2     201502      1     20000930    20210722    19600702      N        1        60    3000       1         1
 3     201512      1     20020125    99991231    19990821      Y        1       130    2000       4         2
 4     201501      3     20011231    20211002    19990821      Y        2        61    3000       2         3
 5     201507      5     20040308    99991231    19661230      Y        2        77    5000       3         4
 6     201508      5     20040308    99991231    19661230      Y        2        77    5000       3         4
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 22 Sep 2022 13:43:41 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-09-22T13:43:41Z</dc:date>
    <item>
      <title>How to assign same number by group with no prime key?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834624#M35893</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
  input date1 kind date2 date3 date4 code1 code2 num tmp_no;
  cards;
  201501 1 20000930 20210722 19600702 N 1 60 2000 1
  201502 1 20000930 20210722 19600702 N 1 60 3000 1
  201501 3 20011231 20211002 19990821 Y 2 61 3000 2
  201507 5 20040308 99991231 19661230 Y 2 77 5000 3
  201508 5 20040308 99991231 19661230 Y 2 77 5000 3
  201512 1 20020125 99991231 19990821 Y 1 130 2000 4
  ;
run;&lt;/PRE&gt;&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;this datasets is extracted from original data since they have null in the key value (identification number by person).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to make temporary number column like tmp_no so that I can see it person by person.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the variables are character except for the 'num'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I searched for a while but other solutions like codes below didn't work.&lt;/P&gt;&lt;PRE&gt;data want;
set have;
by var:;
retain order 0;
if first.var then tmp_no+1; run;&lt;/PRE&gt;&lt;P&gt;I guess it is because none of my columns are key value.&lt;/P&gt;&lt;P&gt;Can you give me a good suggestion for this problem?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot in advance&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, 22 Sep 2022 08:39:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834624#M35893</guid>
      <dc:creator>jorheej</dc:creator>
      <dc:date>2022-09-22T08:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign same number by group with no prime key?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834649#M35897</link>
      <description>&lt;P&gt;Let's take a step back from the computer for a second.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you were looking at this data on a piece of paper, how would you know which rows belong to the same person?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does order matter?&amp;nbsp; For example, would this data represent 2 people or would it represent 4 people?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  201502 1 20000930 20210722 19600702 N 1 60 3000 1
  201501 3 20011231 20211002 19990821 Y 2 61 3000 2
  201502 1 20000930 20210722 19600702 N 1 60 3000 ?
  201501 3 20011231 20211002 19990821 Y 2 61 3000 ?&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Sep 2022 12:08:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834649#M35897</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-09-22T12:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign same number by group with no prime key?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834654#M35898</link>
      <description>&lt;P&gt;Your INPUT statement does not match the number of variables in the data lines.&lt;/P&gt;
&lt;P&gt;Your BY statement does not match the variables in your dataset.&lt;/P&gt;
&lt;P&gt;You are attempting to use a FIRST.xxx variable that does not exist since it was not included in the BY statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like your KEY consists of some, but not all , of the variables.&amp;nbsp; In particular the first "date" and the last "num" are not part of the key.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date1 kind date2 date3 date4 code1 $ code2 num1 num2 tmp_no;
cards;
201501 1 20000930 20210722 19600702 N 1 60 2000 1
201502 1 20000930 20210722 19600702 N 1 60 3000 1
201501 3 20011231 20211002 19990821 Y 2 61 3000 2
201507 5 20040308 99991231 19661230 Y 2 77 5000 3
201508 5 20040308 99991231 19661230 Y 2 77 5000 3
201512 1 20020125 99991231 19990821 Y 1 130 2000 4
;

proc sort ;
  by kind date2 date3 date4 code1 code2 num1 ;
run;

data want;
  set have;
  by kind date2 date3 date4 code1 code2 num1;
  new_num + first.num1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs     date1    kind      date2       date3       date4     code1    code2    num1    num2    tmp_no    new_num

 1     201501      1     20000930    20210722    19600702      N        1        60    2000       1         1
 2     201502      1     20000930    20210722    19600702      N        1        60    3000       1         1
 3     201512      1     20020125    99991231    19990821      Y        1       130    2000       4         2
 4     201501      3     20011231    20211002    19990821      Y        2        61    3000       2         3
 5     201507      5     20040308    99991231    19661230      Y        2        77    5000       3         4
 6     201508      5     20040308    99991231    19661230      Y        2        77    5000       3         4
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2022 13:43:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834654#M35898</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-22T13:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign same number by group with no prime key?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834779#M35903</link>
      <description>Hello,&lt;BR /&gt;I can't tell this data is 2 or 4 people because of the null.&lt;BR /&gt;If those two question marks are 1 and 2,&lt;BR /&gt;it would be 2 persons because they are the same except for the first column.&lt;BR /&gt;But when question marks are 1 and 1,&lt;BR /&gt;it becomes 3 people.&lt;BR /&gt;&lt;BR /&gt;sorry for my ambiguous description &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;</description>
      <pubDate>Fri, 23 Sep 2022 01:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834779#M35903</guid>
      <dc:creator>jorheej</dc:creator>
      <dc:date>2022-09-23T01:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign same number by group with no prime key?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834782#M35904</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;My post has lots of mistakes sorry for that&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&lt;/P&gt;&lt;P&gt;To clarify what I want to do, I write example codes again.&lt;/P&gt;&lt;P&gt;( I want to attach the file I have but it is not possible for the server system that I'm using now)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
  input date1 kind date2 date3 date4 code1 code2 num price;
  cards;
  201501 1 20000930 20210722 19600702 N 1 60 2000 
  201502 1 20000930 20210722 19600702 N 1 60 3000 
  201501 3 20011231 20211002 19990821 Y 2 61 3000 
  201507 5 20040308 99991231 19661230 Y 2 77 5000 
  201508 5 20040308 99991231 19661230 Y 2 77 5000 
  201512 1 20020125 99991231 19990821 Y 1 130 2000 
  ;
run;

data want;
  input date1 kind date2 date3 date4 code1 code2 num price tmp_no;
  cards;
  201501 1 20000930 20210722 19600702 N 1 60 2000 1
  201502 1 20000930 20210722 19600702 N 1 60 3000 1
  201501 3 20011231 20211002 19990821 Y 2 61 3000 2
  201507 5 20040308 99991231 19661230 Y 2 77 5000 3
  201508 5 20040308 99991231 19661230 Y 2 77 5000 3
  201512 1 20020125 99991231 19990821 Y 1 130 2000 4
  ;
run;&lt;/PRE&gt;&lt;P&gt;It seems your solution is setting the num1 as key value&lt;/P&gt;&lt;P&gt;however it might be problem because I have 3,000 rows more and there could be same amount ..&lt;/P&gt;&lt;P&gt;so I think it needs to be considered as it has 8 key values (kind date2 date3 date4 code1 code2 num),&lt;/P&gt;&lt;P&gt;but I'm not sure if it's possible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2022 02:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834782#M35904</guid>
      <dc:creator>jorheej</dc:creator>
      <dc:date>2022-09-23T02:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign same number by group with no prime key?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834785#M35905</link>
      <description>&lt;P&gt;Which variable is a "question mark" in your data?&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2022 02:44:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834785#M35905</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-23T02:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign same number by group with no prime key?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834793#M35909</link>
      <description>There is no 'question mark' in my dataset, I just mentioned that is in &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt; 's code cell &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 23 Sep 2022 03:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834793#M35909</guid>
      <dc:creator>jorheej</dc:creator>
      <dc:date>2022-09-23T03:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign same number by group with no prime key?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834794#M35910</link>
      <description>I think I've done wrong with the input data statement.&lt;BR /&gt;column 'price' needs to be added between num and tmp_no,&lt;BR /&gt;and the tmp_no is what I'm trying to make.&lt;BR /&gt;&lt;BR /&gt;Sorry to confuse.</description>
      <pubDate>Fri, 23 Sep 2022 04:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-assign-same-number-by-group-with-no-prime-key/m-p/834794#M35910</guid>
      <dc:creator>jorheej</dc:creator>
      <dc:date>2022-09-23T04:10:09Z</dc:date>
    </item>
  </channel>
</rss>

