<?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 values based on condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-assign-values-based-on-condition/m-p/502101#M133982</link>
    <description>&lt;P&gt;2 things.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Since you use explicit output statements, you are not guaranteed to get the same number of rows in the two data sets. It will depend on the &lt;STRONG&gt;EXT&amp;nbsp;&lt;/STRONG&gt;variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Since you want to randomly assign values to the &lt;STRONG&gt;EXD&amp;nbsp;&lt;/STRONG&gt;variable if &lt;STRONG&gt;"EXT has pine in it"&lt;/STRONG&gt;, then your if statement is not sufficient.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is not much to go on, but I think this is closer to what you want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t;
	set FDAT;
	period="A";
   array valuespine [3] _temporary_ (5 10 15);
   array valuesRdone [3] _temporary_ (2 4 6);
	if findw(EXT,'pine', 'i')&amp;gt;0 then do;
         EXD=valuespine[rand("integer", 1, 3)];
	end;
	if findw(EXT,'Rdone', 'i')&amp;gt;0 then do;
         EXD=valuesRdone[rand("integer", 1, 3)];
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 06 Oct 2018 10:59:14 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2018-10-06T10:59:14Z</dc:date>
    <item>
      <title>how to assign values based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-assign-values-based-on-condition/m-p/502096#M133978</link>
      <description>&lt;PRE&gt;data t;
	set FDAT;
	period="A";
	if strip(EXT) = "pine" then 
		do;
			EXD = 5;
			output;
			EXD = 10;
			output;
			EXD = 15;
			output;
		end;
		
	if strip(EXT) = "Rdone" then 
		do;
			EXD = 2;
			output;
			EXD = 4;
			output;
			EXD = 6;
			output;
		end;

run;&lt;/PRE&gt;
&lt;P&gt;if my variable EXT has pine in it then i want to assign new variable exd and randomly assign values 5,10,15 for all id's and the same with the next step as mentioned in the code.&lt;/P&gt;
&lt;P&gt;Somehow it doesnt work and creates more records than existing dataset. I am not sure if the logic i am using is correct.&lt;/P&gt;
&lt;P&gt;Any help?&lt;/P&gt;</description>
      <pubDate>Sat, 06 Oct 2018 09:34:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-assign-values-based-on-condition/m-p/502096#M133978</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2018-10-06T09:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign values based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-assign-values-based-on-condition/m-p/502101#M133982</link>
      <description>&lt;P&gt;2 things.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Since you use explicit output statements, you are not guaranteed to get the same number of rows in the two data sets. It will depend on the &lt;STRONG&gt;EXT&amp;nbsp;&lt;/STRONG&gt;variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Since you want to randomly assign values to the &lt;STRONG&gt;EXD&amp;nbsp;&lt;/STRONG&gt;variable if &lt;STRONG&gt;"EXT has pine in it"&lt;/STRONG&gt;, then your if statement is not sufficient.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is not much to go on, but I think this is closer to what you want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t;
	set FDAT;
	period="A";
   array valuespine [3] _temporary_ (5 10 15);
   array valuesRdone [3] _temporary_ (2 4 6);
	if findw(EXT,'pine', 'i')&amp;gt;0 then do;
         EXD=valuespine[rand("integer", 1, 3)];
	end;
	if findw(EXT,'Rdone', 'i')&amp;gt;0 then do;
         EXD=valuesRdone[rand("integer", 1, 3)];
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Oct 2018 10:59:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-assign-values-based-on-condition/m-p/502101#M133982</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-10-06T10:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign values based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-assign-values-based-on-condition/m-p/502120#M133994</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t;
	set FDAT;
	period="A";
	if strip(EXT) = "pine" then 
		do I = 5 to 15 by 5;
			EXD = i;
			output;
		end;
		
	if strip(EXT) = "Rdone" then 
		do I = 2 to 6 by 2;
			EXD = i;
			output;
		end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Oct 2018 14:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-assign-values-based-on-condition/m-p/502120#M133994</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-10-06T14:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign values based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-assign-values-based-on-condition/m-p/502218#M134034</link>
      <description>&lt;P&gt;somehow it does not resolve if i use condition if period="A" then do;&lt;/P&gt;
&lt;P&gt;i get empty values.&lt;/P&gt;
&lt;P&gt;attached test data.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Oct 2018 05:37:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-assign-values-based-on-condition/m-p/502218#M134034</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2018-10-07T05:37:09Z</dc:date>
    </item>
  </channel>
</rss>

