<?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: Create one variable from 3 - based on unique numeric ordering in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68642#M14867</link>
    <description>Your interior DO / END loop is executing 9 times, regardless of the fact that you have assigned your new variable.  I would suggest setting one of the following:&lt;BR /&gt;
&lt;BR /&gt;
1) use the LEAVE statement to exit your DO loops, when appropriate.&lt;BR /&gt;
2) assign both of your DO/END looping variables when you want to continue / iterate to the next observations, using the DIM(i) function in your assignment statement (better than assigning an explicit max value).&lt;BR /&gt;
&lt;BR /&gt;
Also, adding some PUTLOG "&lt;DIAG-NN&gt;" / _ALL_;  statements will help you see the processing -- consider setting up multiple PUTLOGs and use a unique "nn" value for each distinct statement, for easier identification.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/DIAG-NN&gt;</description>
    <pubDate>Sun, 11 Jan 2009 19:50:52 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-01-11T19:50:52Z</dc:date>
    <item>
      <title>Create one variable from 3 - based on unique numeric ordering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68637#M14862</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I'm struggling with what seemed like a simple task - based on the documentation:&lt;BR /&gt;
&lt;BR /&gt;
"2001-Wife/"Wife"'s employment status ER17786, ER17787, ER17788&lt;BR /&gt;
&lt;BR /&gt;
In order to create an equivalent employment status variable for&lt;BR /&gt;
Heads/Wives/"Wives" using the above mentions, a user must consider the code&lt;BR /&gt;
values of all three mentions and prioritize them in order as follows:&lt;BR /&gt;
2,1,3,4,5,7,6,8, 9. For example, if Head had two mentions for employment&lt;BR /&gt;
status, and the first mention was code 1 with the second mention being code 2,&lt;BR /&gt;
then Head's overall employment status would become code 2. If Head had three&lt;BR /&gt;
mentions for employment status with codes of 5, 6, 3, then Head's overall&lt;BR /&gt;
employment status would become code 3."&lt;BR /&gt;
&lt;BR /&gt;
I've tried 2 different arrays - but think I now need to order the 3 employment 'parts' by the odd numeric order before putting them through the array, maybe.  I'll include my 2 attempts below.  The problem is if the new variable is assigned a '2' it can later become a '7' in the code below - which I don't want.&lt;BR /&gt;
&lt;BR /&gt;
Thank you.&lt;BR /&gt;
&lt;BR /&gt;
Attempt 1 at creating a WIFE employment status variable:&lt;BR /&gt;
&lt;BR /&gt;
data test2 (drop=i);&lt;BR /&gt;
set trial1;&lt;BR /&gt;
&lt;BR /&gt;
* rank employment vars;&lt;BR /&gt;
 head_status_01 = .;&lt;BR /&gt;
&lt;BR /&gt;
  array m{3} ER17216-ER17218;&lt;BR /&gt;
&lt;BR /&gt;
   do i=1 to 3 while (head_status_01 = .);&lt;BR /&gt;
&lt;BR /&gt;
if m{i} = 2 then head_status_01 = 2;&lt;BR /&gt;
 else if m{i} = 1 then head_status_01=1;&lt;BR /&gt;
else if m{i} = 3 then head_status_01=3;&lt;BR /&gt;
else if m{i} = 4 then head_status_01=4;&lt;BR /&gt;
else if m{i} = 5 then head_status_01=5;&lt;BR /&gt;
else if m{i} = 7 then head_status_01=7;&lt;BR /&gt;
else if m{i} = 6 then head_status_01=6;&lt;BR /&gt;
else if m{i} = 8 then head_status_01=8;&lt;BR /&gt;
else if m{i} = 9 then head_status_01=9;&lt;BR /&gt;
&lt;BR /&gt;
end;&lt;BR /&gt;
 run;&lt;BR /&gt;
&lt;BR /&gt;
*****************************&lt;BR /&gt;
&lt;BR /&gt;
attempt 2&lt;BR /&gt;
&lt;BR /&gt;
data test2 (drop=i);&lt;BR /&gt;
set trial1 (obs=1000);&lt;BR /&gt;
&lt;BR /&gt;
* rank employment vars;&lt;BR /&gt;
 head_status_01 = .;&lt;BR /&gt;
&lt;BR /&gt;
  array m{3} ER17216-ER17218;&lt;BR /&gt;
array const{9} (2 1 3 4 5 7 6 8 9);&lt;BR /&gt;
      do j=1 to 9;&lt;BR /&gt;
&lt;BR /&gt;
   do i=1 to 3 while (head_status_01 ne .);&lt;BR /&gt;
 if m{i} = const{j} then head_status_01 = const{j};&lt;BR /&gt;
&lt;BR /&gt;
 end;&lt;BR /&gt;
end;&lt;BR /&gt;
 run;</description>
      <pubDate>Sun, 11 Jan 2009 16:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68637#M14862</guid>
      <dc:creator>anjgupta</dc:creator>
      <dc:date>2009-01-11T16:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: Create one variable from 3 - based on unique numeric ordering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68638#M14863</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Could you send the dataset trial1 or a link to it ?&lt;BR /&gt;
&lt;BR /&gt;
I´m not familiar with these documentation, but maybe I could help you with these algorithm.&lt;BR /&gt;
Are you using the default PSID ?&lt;BR /&gt;
&lt;BR /&gt;
I have an ideia and I´d like to make some test´s first.&lt;BR /&gt;
&lt;BR /&gt;
Kassim&lt;BR /&gt;
Brazil</description>
      <pubDate>Sun, 11 Jan 2009 17:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68638#M14863</guid>
      <dc:creator>kassimorra</dc:creator>
      <dc:date>2009-01-11T17:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create one variable from 3 - based on unique numeric ordering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68639#M14864</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Great - I can send the dataset if you provide an email.&lt;BR /&gt;
&lt;BR /&gt;
Yes, this is from the PSID.</description>
      <pubDate>Sun, 11 Jan 2009 17:26:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68639#M14864</guid>
      <dc:creator>anjgupta</dc:creator>
      <dc:date>2009-01-11T17:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: Create one variable from 3 - based on unique numeric ordering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68640#M14865</link>
      <description>Also, consider sending a post-reply with a DATA step that creates an example WORK.TRIAL1  SAS file, using instream DATALINES  and an INPUT statement.  That way you keep focus on the forum subscribers by submitting "sample data" for your original post.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sun, 11 Jan 2009 18:14:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68640#M14865</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-01-11T18:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create one variable from 3 - based on unique numeric ordering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68641#M14866</link>
      <description>Thank you for the sugggestion.  Hope this works.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data trial1;&lt;BR /&gt;
input  ER17216   ER17217   ER17218;&lt;BR /&gt;
datalines;&lt;BR /&gt;
.          .         .&lt;BR /&gt;
.          2         .&lt;BR /&gt;
 1         0         0&lt;BR /&gt;
 1         3         0&lt;BR /&gt;
 1         4         0&lt;BR /&gt;
 1         5         6&lt;BR /&gt;
 1         6         0&lt;BR /&gt;
 1         7         0&lt;BR /&gt;
 1         7         6&lt;BR /&gt;
 1         8         0&lt;BR /&gt;
 2         0         0&lt;BR /&gt;
 2         6         0&lt;BR /&gt;
 3         0         0&lt;BR /&gt;
 3         6         0&lt;BR /&gt;
 3         7         0&lt;BR /&gt;
 4         0         0&lt;BR /&gt;
 4         1         0&lt;BR /&gt;
 4         3         0&lt;BR /&gt;
 4         5         0&lt;BR /&gt;
 4         6         0&lt;BR /&gt;
 5         0         0&lt;BR /&gt;
 5         1         0&lt;BR /&gt;
 5         2         0&lt;BR /&gt;
 5         3         0&lt;BR /&gt;
 5         4         0&lt;BR /&gt;
 5         4         6&lt;BR /&gt;
 5         6         0&lt;BR /&gt;
 5         7         0&lt;BR /&gt;
 6         0         0&lt;BR /&gt;
 6         3         0&lt;BR /&gt;
 6         4         0&lt;BR /&gt;
 6         5         0&lt;BR /&gt;
 6         7         0&lt;BR /&gt;
 6         7         3&lt;BR /&gt;
 6         8         0&lt;BR /&gt;
 7         0         0&lt;BR /&gt;
 7         1         0&lt;BR /&gt;
 7         6         0&lt;BR /&gt;
 8         0         0&lt;BR /&gt;
 8         1         0&lt;BR /&gt;
 8         3         0&lt;BR /&gt;
 8         5         0&lt;BR /&gt;
 8         6         0&lt;BR /&gt;
 ;&lt;BR /&gt;
 run;</description>
      <pubDate>Sun, 11 Jan 2009 18:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68641#M14866</guid>
      <dc:creator>anjgupta</dc:creator>
      <dc:date>2009-01-11T18:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create one variable from 3 - based on unique numeric ordering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68642#M14867</link>
      <description>Your interior DO / END loop is executing 9 times, regardless of the fact that you have assigned your new variable.  I would suggest setting one of the following:&lt;BR /&gt;
&lt;BR /&gt;
1) use the LEAVE statement to exit your DO loops, when appropriate.&lt;BR /&gt;
2) assign both of your DO/END looping variables when you want to continue / iterate to the next observations, using the DIM(i) function in your assignment statement (better than assigning an explicit max value).&lt;BR /&gt;
&lt;BR /&gt;
Also, adding some PUTLOG "&lt;DIAG-NN&gt;" / _ALL_;  statements will help you see the processing -- consider setting up multiple PUTLOGs and use a unique "nn" value for each distinct statement, for easier identification.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/DIAG-NN&gt;</description>
      <pubDate>Sun, 11 Jan 2009 19:50:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68642#M14867</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-01-11T19:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create one variable from 3 - based on unique numeric ordering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68643#M14868</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
Thanks - &lt;BR /&gt;
&lt;BR /&gt;
I considered the leave variable - but it seemed to require the huge if/then combo I was trying to avoid.  That is, when do you leave?  You don't know until the last read if you have a 'better' variable.&lt;BR /&gt;
&lt;BR /&gt;
I do use put statements to help ... and don't quite understand your second suggestion.  If you could expand ...</description>
      <pubDate>Sun, 11 Jan 2009 20:05:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68643#M14868</guid>
      <dc:creator>anjgupta</dc:creator>
      <dc:date>2009-01-11T20:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create one variable from 3 - based on unique numeric ordering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68644#M14869</link>
      <description>With the 2nd code example, the LEAVE "statement" (not variable) will allow you to exit the two nested DO loops immediately, once you have an assigned value for your current observation.  The implied understanding is that you are inputting and outputting once per observation.  Using the PUTLOG with a suffix, allows you to code multiple PUTs (or PUTLOGs) and know which is being executed with you are displaying _ALL_ variables to the log.  I would expect you need to analyze the processing both inside and outside the DO loops to totally understand what's going on in your DATA step.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Sample "very simplified" SAS program to demonstrate using PUTLOG for diagnosis:&lt;BR /&gt;
&lt;BR /&gt;
OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MLOGIC;&lt;BR /&gt;
DATA _NULL_;&lt;BR /&gt;
DO I=1 TO 10;&lt;BR /&gt;
  PUTLOG '&amp;gt;DIAG-01' / _ALL_;&lt;BR /&gt;
  DO J=1 TO 3;  &lt;BR /&gt;
     IF J = 2 THEN PUTLOG '&amp;gt;DIAG-02' / _ALL_;&lt;BR /&gt;
  END;&lt;BR /&gt;
END;&lt;BR /&gt;
PUTLOG '&amp;gt;DIAG-99' / _ALL_;&lt;BR /&gt;
RUN;</description>
      <pubDate>Sun, 11 Jan 2009 21:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68644#M14869</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-01-11T21:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create one variable from 3 - based on unique numeric ordering</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68645#M14870</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Thanks to my brother for this idea - works well.  Basically recode the odd importance of variables to a consecutive order.&lt;BR /&gt;
&lt;BR /&gt;
data test2 (drop=head_status_1 - head_status_3 head_status);&lt;BR /&gt;
set trial1 ;&lt;BR /&gt;
&lt;BR /&gt;
* rank employment vars;&lt;BR /&gt;
 head_status = .;&lt;BR /&gt;
head_status_1 = .;&lt;BR /&gt;
head_status_2 = .;&lt;BR /&gt;
head_status_3 = .;&lt;BR /&gt;
&lt;BR /&gt;
  array weight{2,9} (2 1 3 4 5 7 6 8 9  9 8 7 6  5 4 3 2 1);&lt;BR /&gt;
&lt;BR /&gt;
      do j=1 to 9 until (head_status_1 - head_status_3 ne .) ;&lt;BR /&gt;
&lt;BR /&gt;
if ER17216 = weight(1,j) then head_status_1 = weight(2,j);&lt;BR /&gt;
if ER17217 = weight(1,j) then head_status_2 = weight(2,j);&lt;BR /&gt;
if ER17218 = weight(1,j) then head_status_3 = weight(2,j);&lt;BR /&gt;
if head_status_1 or head_status_2 or head_status_3 = 9 then leave;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
head_status = max(head_status_1, head_status_2, head_status_3);&lt;BR /&gt;
&lt;BR /&gt;
head_status_01 = .;&lt;BR /&gt;
&lt;BR /&gt;
do j=1 to 9 until (head_status_01 ne .);&lt;BR /&gt;
&lt;BR /&gt;
if head_status = weight(2,j) then head_status_01 = weight(1,j);&lt;BR /&gt;
   end;&lt;BR /&gt;
 run;</description>
      <pubDate>Sun, 25 Jan 2009 16:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-one-variable-from-3-based-on-unique-numeric-ordering/m-p/68645#M14870</guid>
      <dc:creator>anjgupta</dc:creator>
      <dc:date>2009-01-25T16:01:40Z</dc:date>
    </item>
  </channel>
</rss>

