<?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 different values by row number or proportion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948929#M371240</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/386642"&gt;@TC_&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;. This solution is neat!&lt;/P&gt;
&lt;P&gt;A follow-up question. If I want to generate the IDs first in one Data step, and assign&amp;nbsp;sem in another Data step, is there a way to do so with a DO Loop? In other words, if I already have a dataset of students' info and want to assign a dropout semester to them, what's the best way to do so with a DO Loop?&lt;/P&gt;
&lt;P&gt;A workaround I have is that I can use your code to create a new dataset, randomly sort the students' info dataset with rng, and merge the two without a BY variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You're welcome. One possible solution is to adapt the code as follows:&lt;/P&gt;
&lt;PRE&gt;/* Create sample data for demonstration */

data have;
id=5;
do _n_=1 to 100;
  id=mod(67*id, 101);
  other_info=ranuni(1);
  output;
end;
run;

/* Assign hypothetical dropout semester */

%let r=0.1;   /* attrition rate */
%let sem1=2;  /* first semester considered */
%let semL=13; /* last semester considered */

data want;
&lt;STRONG&gt;if 0 then set have nobs=n;&lt;/STRONG&gt;
do sem=&amp;amp;sem1 to &amp;amp;semL;
  do &lt;STRONG&gt;_n_&lt;/STRONG&gt;=&lt;STRONG&gt;_n_&lt;/STRONG&gt; to round((1-(1-&amp;amp;r)**(sem-&amp;amp;sem1+1))*&lt;STRONG&gt;n&lt;/STRONG&gt;);
    &lt;STRONG&gt;link rw;&lt;/STRONG&gt;
  end;
end;
sem=.;
do &lt;STRONG&gt;_n_&lt;/STRONG&gt;=&lt;STRONG&gt;_n_&lt;/STRONG&gt; to &lt;STRONG&gt;n&lt;/STRONG&gt;; /* these never drop out */
  &lt;STRONG&gt;link rw;&lt;/STRONG&gt;
end;
&lt;STRONG&gt;rw:
  set have;
  output;&lt;/STRONG&gt;
run;&lt;/PRE&gt;</description>
    <pubDate>Thu, 24 Oct 2024 16:21:21 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2024-10-24T16:21:21Z</dc:date>
    <item>
      <title>How to assign different values by row number or proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948859#M371214</link>
      <description>&lt;P&gt;I want to simulate student attrition. I have a bunch of student currently enrolled, assume starting the 2nd semester, 10% of those who are still enrolled drop out each semester. So with 100 students, the number of students dropping out is 10, 9, 8, 7...&lt;/P&gt;
&lt;P&gt;I want to create a variable (2,3,4...) indicating which semester the students drop out. This is the dataset I start with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data records;
	do ID=1 to 100;
	output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And I want to get results like this below (no randomness at all)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TC__0-1729750499932.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101760i3CB6447FB9CCBD2B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TC__0-1729750499932.png" alt="TC__0-1729750499932.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also need to apply this program to other scenarios where the attrition rate and number of students may differ. This is what I am doing and it works.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let attr_rate=0.10;&lt;BR /&gt;data proj3;
	set proj2 nobs=_nobs_; *_nobs_=number of rows;

	if _N_&amp;lt;=round(_nobs_*&amp;amp;attr_rate) then last_sem=2;
	else if _N_&amp;lt;=round(_nobs_*&amp;amp;attr_rate)+round(_nobs_*(1-&amp;amp;attr_rate)*&amp;amp;attr_rate) then last_sem=3;
	else if _N_&amp;lt;=round(_nobs_*&amp;amp;attr_rate)+round(_nobs_*(1-&amp;amp;attr_rate)*&amp;amp;attr_rate)+round(_nobs_*(1-&amp;amp;attr_rate)**2*&amp;amp;attr_rate) then last_sem=4;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But as you can see, the code gets really long as I cover more semesters. And I have up to 13 semesters to cover.&lt;/P&gt;
&lt;P&gt;Is there a better and/or smarter way to achieve this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much!&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, 24 Oct 2024 06:41:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948859#M371214</guid>
      <dc:creator>TC_</dc:creator>
      <dc:date>2024-10-24T06:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different values by row number or proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948863#M371216</link>
      <description>&lt;P&gt;Very interesting question.&lt;/P&gt;
&lt;P&gt;If I understood what you mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;


data records;
	do ID=1 to 100;
	output;
	end;
run;

data temp;
drop=2;n=10;  /*initial value*/
do until(n=0);
do i=1 to n;
 output;
end;
n+(-1);
drop+1;
end;
drop i;
run;

data want;
 merge records temp;
run;

proc freq data=want;
table drop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1729759772931.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101761iF9533B416332513D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1729759772931.png" alt="Ksharp_0-1729759772931.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 08:49:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948863#M371216</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-10-24T08:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different values by row number or proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948867#M371218</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/386642"&gt;@TC_&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would use the cumulative number of dropped out students:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let r=0.1;   /* attrition rate */
%let n=100;   /* initial number of students */
%let sem1=2;  /* first semester considered */
%let semL=13; /* last semester considered */

data want;
ID=1;
do sem=&amp;amp;sem1 to &amp;amp;semL;
  do ID=ID to round((1-(1-&amp;amp;r)**(sem-&amp;amp;sem1+1))*&amp;amp;n);
    output;
  end;
end;
sem=.;
do ID=ID to &amp;amp;n; /* these never drop out */
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Oct 2024 10:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948867#M371218</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-10-24T10:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different values by row number or proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948879#M371219</link>
      <description>&lt;P&gt;I interpreted your question a bit differently than&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;(...which is daring...).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe the formula to calculate the survival rate for a student after n semesters with a drop out probability p of 0.1 per semesters would be:&amp;nbsp;S(n) = (1-p)&lt;SUP&gt;n&lt;/SUP&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I couldn't figure out a way that doesn't require a loop for calculating the drop out semester. Soo.... here I go:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n_semesters=13;
%let drop_probability=0.1;
data have;
  do semester=1 to &amp;amp;n_semesters;
    do i=1 to 10000;
      student_id=cats(semester,'_',i);
      output;
    end;
  end;
  drop i;
run;

data want;
  set have;
  if _n_=1 then call streaminit(1230497);

  drop_out_flg=0;
  do i=1 to semester;
    if rand('uniform')&amp;lt;=&amp;amp;drop_probability then
      do;
        drop_out_flg=1;
        drop_out_semester=i;
        leave;
      end;
  end;
run;

%let sv_missing=%sysfunc(getoption(missing,keyword));
options missing=' ';
title 'drop/no drop per semester';
proc tabulate data=want noseps missing;
  keylabel n=' ';
  class drop_out_flg drop_out_semester;
  table drop_out_semester all='Total', drop_out_flg;
run;
title;
options &amp;amp;sv_missing;

/* as a check: calculate survival for a student over all remaining semesters */
%let sv_missing=%sysfunc(getoption(missing,keyword));
options missing=' ';
data survival;
  set have;
  if _n_=1 then call streaminit(1230497);

  drop_out_flg=0;
  if rand('uniform')&amp;gt;(1-&amp;amp;drop_probability)**semester then drop_out_flg=1;
run;

title 'survival over all semesters';
proc tabulate data=survival noseps missing;
  keylabel n=' ';
  class drop_out_flg;
  table drop_out_flg;
run;
title;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1729774333575.png" style="width: 202px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101764i5760496CCA7527B9/image-dimensions/202x525?v=v2" width="202" height="525" role="button" title="Patrick_1-1729774333575.png" alt="Patrick_1-1729774333575.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 12:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948879#M371219</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-10-24T12:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different values by row number or proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948914#M371230</link>
      <description>&lt;P&gt;Thank you for responding, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;I guess I should have highlighted how I wanted to use the program at the beginning. I need to use the program in other scenarios where the attrition rate might differ. The example of 100 students with 10% dropout was given as an example to make things easier to follow. I might have, say, 57 students with 5% attrition rate; or 165 students with 7% attrition rate. What you provided is more like a way to generate a sequence of numbers with a specific frequency.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 15:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948914#M371230</guid>
      <dc:creator>TC_</dc:creator>
      <dc:date>2024-10-24T15:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different values by row number or proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948918#M371233</link>
      <description>&lt;P&gt;Thank you very much,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;. This solution is neat!&lt;/P&gt;
&lt;P&gt;A follow-up question. If I want to generate the IDs first in one Data step, and assign&amp;nbsp;sem in another Data step, is there a way to do so with a DO Loop? In other words, if I already have a dataset of students' info and want to assign a dropout semester to them, what's the best way to do so with a DO Loop?&lt;/P&gt;
&lt;P&gt;A workaround I have is that I can use your code to create a new dataset, randomly sort the students' info dataset with rng, and merge the two without a BY variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 15:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948918#M371233</guid>
      <dc:creator>TC_</dc:creator>
      <dc:date>2024-10-24T15:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different values by row number or proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948919#M371234</link>
      <description>&lt;P&gt;Thank you,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;. I wanted to use random assignment as well, but my supervisor explicitly said not to do so at this point. Anyway, I like your random assignment. At this point, this is not what I wanted, but it will surely be helpful to keep in mind for my future work.&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 15:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948919#M371234</guid>
      <dc:creator>TC_</dc:creator>
      <dc:date>2024-10-24T15:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different values by row number or proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948926#M371238</link>
      <description>&lt;P&gt;Should be able to use the NOBS= option of the SET statement to know how many to put into each group.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let rate=0.10 ;

data want;
  retain obs 1 semester 2;
  do obs=obs to obs+int(&amp;amp;rate*(nobs-obs));
    set records nobs=nobs;
    output;
  end;
  semester+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1729786223877.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101777i8374D5EB85A91F4E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1729786223877.png" alt="Tom_0-1729786223877.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_1-1729786251182.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101778i0D852A64938E84EA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_1-1729786251182.png" alt="Tom_1-1729786251182.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_2-1729786434498.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101779iA99DE5F79C70EADD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_2-1729786434498.png" alt="Tom_2-1729786434498.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 16:14:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948926#M371238</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-24T16:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different values by row number or proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948929#M371240</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/386642"&gt;@TC_&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;. This solution is neat!&lt;/P&gt;
&lt;P&gt;A follow-up question. If I want to generate the IDs first in one Data step, and assign&amp;nbsp;sem in another Data step, is there a way to do so with a DO Loop? In other words, if I already have a dataset of students' info and want to assign a dropout semester to them, what's the best way to do so with a DO Loop?&lt;/P&gt;
&lt;P&gt;A workaround I have is that I can use your code to create a new dataset, randomly sort the students' info dataset with rng, and merge the two without a BY variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You're welcome. One possible solution is to adapt the code as follows:&lt;/P&gt;
&lt;PRE&gt;/* Create sample data for demonstration */

data have;
id=5;
do _n_=1 to 100;
  id=mod(67*id, 101);
  other_info=ranuni(1);
  output;
end;
run;

/* Assign hypothetical dropout semester */

%let r=0.1;   /* attrition rate */
%let sem1=2;  /* first semester considered */
%let semL=13; /* last semester considered */

data want;
&lt;STRONG&gt;if 0 then set have nobs=n;&lt;/STRONG&gt;
do sem=&amp;amp;sem1 to &amp;amp;semL;
  do &lt;STRONG&gt;_n_&lt;/STRONG&gt;=&lt;STRONG&gt;_n_&lt;/STRONG&gt; to round((1-(1-&amp;amp;r)**(sem-&amp;amp;sem1+1))*&lt;STRONG&gt;n&lt;/STRONG&gt;);
    &lt;STRONG&gt;link rw;&lt;/STRONG&gt;
  end;
end;
sem=.;
do &lt;STRONG&gt;_n_&lt;/STRONG&gt;=&lt;STRONG&gt;_n_&lt;/STRONG&gt; to &lt;STRONG&gt;n&lt;/STRONG&gt;; /* these never drop out */
  &lt;STRONG&gt;link rw;&lt;/STRONG&gt;
end;
&lt;STRONG&gt;rw:
  set have;
  output;&lt;/STRONG&gt;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Oct 2024 16:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948929#M371240</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-10-24T16:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different values by row number or proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948991#M371266</link>
      <description>&lt;P&gt;OK. You need to change the initial value. Here is an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*165 students with 7% attrition rate*/

data records;
	do ID=1 to 165;  /*165 students */
	output;
	end;
run;

data temp;
drop=2;n=12;  /* 12=ceil(165*0.07) */
do until(n=0);
do i=1 to n;
 output;
end;
n+(-1);
drop+1;
end;
drop i;
run;

data want;
 merge records temp;
run;

proc freq data=want;
table drop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Oct 2024 01:02:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/948991#M371266</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-10-25T01:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different values by row number or proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/949000#M371272</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Read the entire dataset, using the NOBS= parameter with the drop rate to generate the&amp;nbsp; target drop count for the initial LAST_SEM value.&amp;nbsp; Then as the target for each semester is reached, update the target through the final eligible LAST_SEM, after which LAST_SEM is set to missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do id=1 to 100; output; end;
run;

%let rate=.1;
%let beg_drop=2;
%let end_drop=10;

data want;
  retain last_sem &amp;amp;beg_drop _target 0 ;

  set have nobs=nrecs;
  if _n_=1 then _target=round(&amp;amp;rate * nrecs);
  output;

  if _n_= _target then do;
    last_sem+1;
    _target + round(&amp;amp;rate * (nrecs-_n_));
    if last_sem&amp;gt;&amp;amp;end_drop then call missing(last_sem,_target);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, this assumes that the nobs of HAVE and the dropout rate will generate at least one dropout in the first eligible time period.&amp;nbsp; If that is a possible issue, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
  retain last_sem &amp;amp;beg_drop _target 0 ;

  set have nobs=nrecs;
  if _n_=1 then do;
    _target=round(&amp;amp;rate * nrecs);
    if _target=0 then call missing(last_sem,_target);
  end;
  output;

  if _n_= _target then do;
    last_sem+1;
    _target + round(&amp;amp;rate * (nrecs-_n_));
    if last_sem&amp;gt;&amp;amp;end_drop then call missing(last_sem,_target);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Oct 2024 03:42:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/949000#M371272</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-10-25T03:42:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different values by row number or proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/949009#M371274</link>
      <description>Awesome, thank you!</description>
      <pubDate>Fri, 25 Oct 2024 06:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/949009#M371274</guid>
      <dc:creator>TC_</dc:creator>
      <dc:date>2024-10-25T06:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different values by row number or proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/949010#M371275</link>
      <description>&lt;P&gt;Thank you, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;! This solution also gets the job done and is quite concise. I really wish I could accept two solutions.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 06:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/949010#M371275</guid>
      <dc:creator>TC_</dc:creator>
      <dc:date>2024-10-25T06:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to assign different values by row number or proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/949013#M371278</link>
      <description>Thank you for your response and the explanation!</description>
      <pubDate>Fri, 25 Oct 2024 07:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-assign-different-values-by-row-number-or-proportion/m-p/949013#M371278</guid>
      <dc:creator>TC_</dc:creator>
      <dc:date>2024-10-25T07:04:04Z</dc:date>
    </item>
  </channel>
</rss>

