<?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: re: Assign Numbers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/re-Assign-Numbers/m-p/803414#M316337</link>
    <description>&lt;P&gt;Hi Ballardw,.... When GrNumber is missing and the Color is either Red, Orange or Blue, then the BagNumber is 1 since the GrNumber is 1 when the Color is Orange. Hope that helps.&lt;/P&gt;</description>
    <pubDate>Tue, 22 Mar 2022 18:19:38 GMT</pubDate>
    <dc:creator>twildone</dc:creator>
    <dc:date>2022-03-22T18:19:38Z</dc:date>
    <item>
      <title>re: Assign Numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-Assign-Numbers/m-p/803396#M316331</link>
      <description>&lt;P&gt;Hi,..Suppose I have several boxes of marbles and would like to put them in separate bags based on the color of the marble. I would like to put specific colors in each bag where the bag is assigned a BagNumber based on the specific GrNumber for one of the colors that will be assigned to each bag. I have tried the code below but I am not getting all of BagNumbers assigned. Any suggestions on how to get all BagNumbers assigned....Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data Have;
  infile datalines truncover;
  input BoxNumber Color $ GrNumber;
  datalines;
1 Red .
1 Orange .
1 Orange 1
1 Red .
1 Blue .
1 Black .
1 Blue .
1 Black .
1 Black .
1 White 2
1 Black .
1 White .
1 Green 3
1 Yellow .
1 White .
2 Red .
2 Orange 1
2 Blue .
2 Black .
2 Blue .
2 White .
2 Black .
2 White 2
;

proc sort data=Have;
	by BoxNumber Color;
run;

data Want;
	do _n_ = 1 by 1 until (last.Color);
	set Have;
	by BoxNumber Color;
			if GrNumber in (1) and Color in ('Red','Orange','Blue') and missing(BagNumber) then
					BagNumber=1;
			else			 
			if GrNumber in (2) and Color in ('White','Black') and missing(BagNumber) then
					BagNumber=2;
			else			 			 
			if GrNumber in (3) and Color in ('Green','Yellow') and missing(BagNumber) then
					BagNumber=3;
			output;
		end;
run; 

Want:
BoxNumber	Color	GrNumber	BagNumber
1	Black		2
1	Black		2
1	Black		2
1	Black		2
1	Blue		1
1	Blue		1
1	Green	3	3
1	Orange		1
1	Orange	1	1
1	Red		1
1	Red		1
1	White	2	2
1	White		2
1	White		2
1	Yellow		3
2	Black		2
2	Black		2
2	Blue		1
2	Blue		1
2	Orange	1	1
2	Red		1
2	White		2
2	White	2	2
&lt;/PRE&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;
&lt;P&gt;&amp;nbsp;&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>Tue, 22 Mar 2022 17:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-Assign-Numbers/m-p/803396#M316331</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2022-03-22T17:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: re: Assign Numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-Assign-Numbers/m-p/803410#M316333</link>
      <description>&lt;P&gt;You code isn't doing what you want because you have 3 comparisons that all start with "if GrNumber in (&amp;lt;some value&amp;gt;)" but most of your data is missing GrNumber.&lt;/P&gt;
&lt;P&gt;So what is the rule of what is supposed to be done when the GrNumber is missing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4061"&gt;@twildone&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,..Suppose I have several boxes of marbles and would like to put them in separate bags based on the color of the marble. I would like to put specific colors in each bag where the bag is assigned a BagNumber based on the specific GrNumber for one of the colors that will be assigned to each bag. I have tried the code below but I am not getting all of BagNumbers assigned. Any suggestions on how to get all BagNumbers assigned....Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data Have;
  infile datalines truncover;
  input BoxNumber Color $ GrNumber;
  datalines;
1 Red .
1 Orange .
1 Orange 1
1 Red .
1 Blue .
1 Black .
1 Blue .
1 Black .
1 Black .
1 White 2
1 Black .
1 White .
1 Green 3
1 Yellow .
1 White .
2 Red .
2 Orange 1
2 Blue .
2 Black .
2 Blue .
2 White .
2 Black .
2 White 2
;

proc sort data=Have;
	by BoxNumber Color;
run;

data Want;
	do _n_ = 1 by 1 until (last.Color);
	set Have;
	by BoxNumber Color;
			if GrNumber in (1) and Color in ('Red','Orange','Blue') and missing(BagNumber) then
					BagNumber=1;
			else			 
			if GrNumber in (2) and Color in ('White','Black') and missing(BagNumber) then
					BagNumber=2;
			else			 			 
			if GrNumber in (3) and Color in ('Green','Yellow') and missing(BagNumber) then
					BagNumber=3;
			output;
		end;
run; 

Want:
BoxNumber	Color	GrNumber	BagNumber
1	Black		2
1	Black		2
1	Black		2
1	Black		2
1	Blue		1
1	Blue		1
1	Green	3	3
1	Orange		1
1	Orange	1	1
1	Red		1
1	Red		1
1	White	2	2
1	White		2
1	White		2
1	Yellow		3
2	Black		2
2	Black		2
2	Blue		1
2	Blue		1
2	Orange	1	1
2	Red		1
2	White		2
2	White	2	2
&lt;/PRE&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;
&lt;P&gt;&amp;nbsp;&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;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 17:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-Assign-Numbers/m-p/803410#M316333</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-22T17:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: re: Assign Numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-Assign-Numbers/m-p/803414#M316337</link>
      <description>&lt;P&gt;Hi Ballardw,.... When GrNumber is missing and the Color is either Red, Orange or Blue, then the BagNumber is 1 since the GrNumber is 1 when the Color is Orange. Hope that helps.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 18:19:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-Assign-Numbers/m-p/803414#M316337</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2022-03-22T18:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: re: Assign Numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-Assign-Numbers/m-p/803439#M316353</link>
      <description>&lt;P&gt;What about GrNumber missing and colors other than Red, Orange or Blue??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Partial rules= partial solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can test for missing values using either the Missing function: If Missing(variable) then &amp;lt;do something&amp;gt;&lt;/P&gt;
&lt;P&gt;or use the comparison with a value of .&amp;nbsp;&amp;nbsp; If variable = . then &amp;lt;do something&amp;gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 19:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-Assign-Numbers/m-p/803439#M316353</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-22T19:15:55Z</dc:date>
    </item>
  </channel>
</rss>

