<?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 Making ID variable without any other information in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Making-ID-variable-without-any-other-information/m-p/504959#M135204</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having trouble creating an ID variable because there are no other variables in the data set for me to use the first.variable trick to create an ID variable. Here is a description of the data. The labels Response_1 through Response_N represent repeated measurements for individuals. I would like to create for the first 12 lines, ID = 1 and for the next 12 lines, ID = 2 all the way until ID = 228. The variable Iter represents the iteration number for this simulated data. &lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screen Shot 2018-10-16 at 8.34.19 PM.png" style="width: 322px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/24068iA00AD55573863381/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-10-16 at 8.34.19 PM.png" alt="Screen Shot 2018-10-16 at 8.34.19 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Please let me know if there's anything I can do to clarify what I did. Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Tim&lt;/P&gt;</description>
    <pubDate>Wed, 17 Oct 2018 03:37:12 GMT</pubDate>
    <dc:creator>tbanh</dc:creator>
    <dc:date>2018-10-17T03:37:12Z</dc:date>
    <item>
      <title>Making ID variable without any other information</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-ID-variable-without-any-other-information/m-p/504959#M135204</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having trouble creating an ID variable because there are no other variables in the data set for me to use the first.variable trick to create an ID variable. Here is a description of the data. The labels Response_1 through Response_N represent repeated measurements for individuals. I would like to create for the first 12 lines, ID = 1 and for the next 12 lines, ID = 2 all the way until ID = 228. The variable Iter represents the iteration number for this simulated data. &lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screen Shot 2018-10-16 at 8.34.19 PM.png" style="width: 322px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/24068iA00AD55573863381/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-10-16 at 8.34.19 PM.png" alt="Screen Shot 2018-10-16 at 8.34.19 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Please let me know if there's anything I can do to clarify what I did. Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Tim&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 03:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-ID-variable-without-any-other-information/m-p/504959#M135204</guid>
      <dc:creator>tbanh</dc:creator>
      <dc:date>2018-10-17T03:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Making ID variable without any other information</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-ID-variable-without-any-other-information/m-p/504962#M135206</link>
      <description>&lt;P&gt;Can't you just use arithmetic to make the new variable?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  id = 1+int((_n_-1)/12);
  set have ;
run;
  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Oct 2018 04:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-ID-variable-without-any-other-information/m-p/504962#M135206</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-17T04:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: Making ID variable without any other information</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-ID-variable-without-any-other-information/m-p/504991#M135215</link>
      <description>&lt;P&gt;I'm not quite sure I completly get what you are trying to say - Are you saying you want an the same ID for the first 12 Lines and after that keep increasing the id - if so:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.aa1;
 set your_input;
 if _n_ lt 13 then id eq 1;
 else id = id + 1;
 retain id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you always have 12 responses than you could to something like this - using the&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl/en/imlug/64248/HTML/default/viewer.htm#imlug_langref_sect193.htm" target="_self"&gt;mod function&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.aa2;
 set your_input;
 if _n_ eq 1 then id eq 1;
 else if mod(_n_,13) eq 0 then id = id + 1;
 retain id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if you need a new id every line&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.aa3;
 set your_input;
 id = _n_;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Oct 2018 08:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-ID-variable-without-any-other-information/m-p/504991#M135215</guid>
      <dc:creator>Criptic</dc:creator>
      <dc:date>2018-10-17T08:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: Making ID variable without any other information</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-ID-variable-without-any-other-information/m-p/505232#M135276</link>
      <description>&lt;P&gt;This works! Thank you so much Tom. One more question. Per each iteration, I have 228 subjects. The code you provided works for the first iteration but for Iter = 2, as you can see in the picture, SUBID starts back at 1, which I would like, but it does not repeat the same procedure as for Iter = 1. Here is the code I used to generate the data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long2;
  set long1;
  SUBID = 1 + int((_n_-1)/12);
  by Iter; 
  if first.Iter then SUBID = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screen Shot 2018-10-17 at 10.33.22 AM.png" style="width: 395px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/24095i0E93AD7E345C97D1/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-10-17 at 10.33.22 AM.png" alt="Screen Shot 2018-10-17 at 10.33.22 AM.png" /&gt;&lt;/span&gt;&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>Wed, 17 Oct 2018 17:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-ID-variable-without-any-other-information/m-p/505232#M135276</guid>
      <dc:creator>tbanh</dc:creator>
      <dc:date>2018-10-17T17:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: Making ID variable without any other information</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-ID-variable-without-any-other-information/m-p/505242#M135278</link>
      <description>&lt;P&gt;Keep your own counter per ITER instead of use the automatic _N_ variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;row+1; 
if first.ITER then row=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can use a DO Loop around the SET statement, note that means you need to add an OUTPUT statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long2;
do row=1 by 1 until(last.Iter);
  set long1;
  by Iter; 
  SUBID = 1 + int((ROW-1)/12);
  output;
end;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Or better just use two DO loops.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long2;
do SUBJID=1 by 1 until(last.iter);
  do row=1 to 12 until(last.Iter);
    set long1;
    by Iter; 
    output;
  end;
end;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Oct 2018 18:21:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-ID-variable-without-any-other-information/m-p/505242#M135278</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-17T18:21:11Z</dc:date>
    </item>
  </channel>
</rss>

