<?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: Changing subject's ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795468#M255162</link>
    <description>&lt;P&gt;I don't understand this. Why 1, 1, 1 and 2, 2, 2 ?&lt;/P&gt;</description>
    <pubDate>Thu, 10 Feb 2022 12:10:49 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-02-10T12:10:49Z</dc:date>
    <item>
      <title>Changing subject's ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795467#M255161</link>
      <description>&lt;P&gt;This is a subset of a larger data. The data was generated by a biochemist and I have an issue with the subjects' IDs.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"METAPH" is the name of the study. Subjects are&amp;nbsp; measured at 3 occasions (S1-1, S3-1 and S5-1). The subject's ID is as follow: occasion-study'name-subject. For example the first subject has 3 IDs corresponding to the 3 measurements:&lt;/P&gt;&lt;P&gt;S1-1-METAPH-002&lt;/P&gt;&lt;P&gt;S3-1-METAPH-002&lt;/P&gt;&lt;P&gt;S5-1-METAPH-002&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data looks like it was manually entered:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SUBJECT&lt;BR /&gt;S1-1-METAPH-002&lt;BR /&gt;S1-1-METAPH-019&lt;BR /&gt;S1-1-METAPH-089&lt;BR /&gt;S1-1-METAPH-027&lt;BR /&gt;S1-1-METAPH-006&lt;BR /&gt;S1-1-METAPH-007&lt;BR /&gt;S1-1-METAPH-008&lt;BR /&gt;S1-1-METAPH-003&lt;BR /&gt;S3-1-METAPH-027&lt;BR /&gt;S3-1-METAPH-008&lt;BR /&gt;S3-1-METAPH-089&lt;BR /&gt;S3-1-METAPH-003&lt;BR /&gt;S3-1-METAPH-002&lt;BR /&gt;S3-1-METAPH-006&lt;BR /&gt;S3-1-METAPH-007&lt;BR /&gt;S3-1-METAPH-019&lt;BR /&gt;S5-1-METAPH-002&lt;BR /&gt;S5-1-METAPH-003&lt;BR /&gt;S5-1-METAPH-027&lt;BR /&gt;S5-1-METAPH-089&lt;BR /&gt;S5-1-METAPH-006&lt;BR /&gt;S5-1-METAPH-019&lt;BR /&gt;S5-1-METAPH-008&lt;BR /&gt;S5-1-METAPH-007&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to replace&amp;nbsp; these 3 IDs by only one, which is 1, and the data to look like:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 11:59:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795467#M255161</guid>
      <dc:creator>Job04</dc:creator>
      <dc:date>2022-02-10T11:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: Changing subject's ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795468#M255162</link>
      <description>&lt;P&gt;I don't understand this. Why 1, 1, 1 and 2, 2, 2 ?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 12:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795468#M255162</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-02-10T12:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: Changing subject's ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795471#M255163</link>
      <description>&lt;P&gt;Is that the only pattern that we need to be aware of? In other words, is it S[digit]-[number]? If so, this is a bit clunky but works for this instance.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input subject $20.;
datalines;
S1-1-METAPH-002
S1-1-METAPH-019
S1-1-METAPH-089
S1-1-METAPH-027
S1-1-METAPH-006
S1-1-METAPH-007
S1-1-METAPH-008
S1-1-METAPH-003
S3-1-METAPH-027
S3-1-METAPH-008
S3-1-METAPH-089
S3-1-METAPH-003
S3-1-METAPH-002
S3-1-METAPH-006
S3-1-METAPH-007
S3-1-METAPH-019
S5-1-METAPH-002
S5-1-METAPH-003
S5-1-METAPH-027
S5-1-METAPH-089
S5-1-METAPH-006
S5-1-METAPH-019
S5-1-METAPH-008
S5-1-METAPH-007
;
run;

proc sort
	data = have;
		by subject;
run;

data have_2;
	set have;
		id = catx("-", scan(subject, 1, '-'), scan(subject, 2, '-'));
run;

proc sort
	data = have_2;
		by id;
run;

data want;
	set have_2;
	by id;
	retain new_id;
		if first.id then new_id + 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs subject id new_id 
1 S1-1-METAPH-002 S1-1 1 
2 S1-1-METAPH-003 S1-1 1 
3 S1-1-METAPH-006 S1-1 1 
4 S1-1-METAPH-007 S1-1 1 
5 S1-1-METAPH-008 S1-1 1 
6 S1-1-METAPH-019 S1-1 1 
7 S1-1-METAPH-027 S1-1 1 
8 S1-1-METAPH-089 S1-1 1 
9 S3-1-METAPH-002 S3-1 2 
10 S3-1-METAPH-003 S3-1 2 
11 S3-1-METAPH-006 S3-1 2 
12 S3-1-METAPH-007 S3-1 2 
13 S3-1-METAPH-008 S3-1 2 
14 S3-1-METAPH-019 S3-1 2 
15 S3-1-METAPH-027 S3-1 2 
16 S3-1-METAPH-089 S3-1 2 
17 S5-1-METAPH-002 S5-1 3 
18 S5-1-METAPH-003 S5-1 3 
19 S5-1-METAPH-006 S5-1 3 
20 S5-1-METAPH-007 S5-1 3 
21 S5-1-METAPH-008 S5-1 3 
22 S5-1-METAPH-019 S5-1 3 
23 S5-1-METAPH-027 S5-1 3 
24 S5-1-METAPH-089 S5-1 3 
&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Feb 2022 12:59:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795471#M255163</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2022-02-10T12:59:13Z</dc:date>
    </item>
    <item>
      <title>Re: Changing subject's ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795472#M255164</link>
      <description>&lt;P&gt;As you can see the IDs are not sequential perhaps some subjects were exluded from the&amp;nbsp; study. I would like to&amp;nbsp; identify subjects by their numbers in the study and not by this long and confusing ID. I have another column that specifies the time of measurement (S1,S3&amp;nbsp; and S5) which I can use in my modeling. For example these 3 measurements of patient 002 I want to have 3&amp;nbsp; records called 002. In other word, I want to leave only the three digits to the far right of this long ID. I hope I answered your question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 13:01:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795472#M255164</guid>
      <dc:creator>Job04</dc:creator>
      <dc:date>2022-02-10T13:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Changing subject's ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795477#M255166</link>
      <description>&lt;P&gt;I didn't well explain what I needed. As you put it:&amp;nbsp;&lt;SPAN&gt;S[digit]-[number]:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I needed only to keep the "number".&amp;nbsp; I have another column in the dataset to control when measurement was taken. This is longitudinal study&amp;nbsp; so I should have 3 identical ID number per subjet.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 13:46:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795477#M255166</guid>
      <dc:creator>Job04</dc:creator>
      <dc:date>2022-02-10T13:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: Changing subject's ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795481#M255167</link>
      <description>&lt;P&gt;Alright, I misunderstood your question. Do you mind replacing the `.` in the id field in this DATALINES statement with exactly what you want?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input subject :$20. id;
datalines;
S1-1-METAPH-002 .
S1-1-METAPH-019 .
S1-1-METAPH-089 .
S1-1-METAPH-027 .
S1-1-METAPH-006 .
S1-1-METAPH-007 .
S1-1-METAPH-008 .
S1-1-METAPH-003 .
S3-1-METAPH-027 .
S3-1-METAPH-008 .
S3-1-METAPH-089 .
S3-1-METAPH-003 .
S3-1-METAPH-002 .
S3-1-METAPH-006 .
S3-1-METAPH-007 .
S3-1-METAPH-019 .
S5-1-METAPH-002 .
S5-1-METAPH-003 .
S5-1-METAPH-027 .
S5-1-METAPH-089 .
S5-1-METAPH-006 .
S5-1-METAPH-019 .
S5-1-METAPH-008 .
S5-1-METAPH-007 .
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can copy this code, and in your reply use the `insert SAS code` button and replace the `.` with your desired values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will help us figure out the solution.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 14:05:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795481#M255167</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2022-02-10T14:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: Changing subject's ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795489#M255169</link>
      <description>&lt;P&gt;If I understand you correctly, you want to get the last 3 digits from the subject variable, which identifies the patient. One way is this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length id $3;
  id=scan(subject,-1,'-');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Feb 2022 14:26:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795489#M255169</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-02-10T14:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Changing subject's ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795495#M255171</link>
      <description>&lt;P&gt;Sorry for not explaining straight to the point what I needed.&amp;nbsp; It was so simple to say I want to keep the last 3 digits.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 14:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-subject-s-ID/m-p/795495#M255171</guid>
      <dc:creator>Job04</dc:creator>
      <dc:date>2022-02-10T14:54:33Z</dc:date>
    </item>
  </channel>
</rss>

