<?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: Creating Variable based on reading data across the row. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262426#M51220</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/3913"&gt;@Sotarkadin&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;The status is not controlled by the date but by which action has a date. &amp;nbsp;Each of those actions could happen on the same date but they do happen in order. &amp;nbsp;It is opened, then act1, act2, etc.. until it's closed. &amp;nbsp;The last action to occur tells me where it is at in the process. &amp;nbsp;The close_dt is the last one as not all of the actions have to occur before it's closed. &amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In that case the order of the variables in the array matter. So place them in decreasing order of status. So ties will go to the highest status. &amp;nbsp;closed,...act2,act1,opened.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Apr 2016 13:44:59 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2016-04-08T13:44:59Z</dc:date>
    <item>
      <title>Creating Variable based on reading data across the row.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262226#M51147</link>
      <description>&lt;P&gt;I currently have a data set that has columns with different dates for when actions have occured. &amp;nbsp;I need to create a column with the stauts based on which column is the last to have a date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example Data&amp;amp;colon;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OBS &amp;nbsp; &amp;nbsp; Account # &amp;nbsp; &amp;nbsp; open_dt &amp;nbsp; &amp;nbsp; &amp;nbsp; act1_dt &amp;nbsp; &amp;nbsp; &amp;nbsp; act2_dt &amp;nbsp; &amp;nbsp; &amp;nbsp;act3_dt &amp;nbsp; &amp;nbsp; &amp;nbsp; act4_dt &amp;nbsp; &amp;nbsp;close_dt &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;123456 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3/1/16&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 23456 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3/1/16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3/3/16&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 34567 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3/13/16 &amp;nbsp; &amp;nbsp; 3/15/16 &amp;nbsp; &amp;nbsp; &amp;nbsp;3/17/16 &amp;nbsp; &amp;nbsp; &amp;nbsp; 3/18/16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3/20/16&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to create a column called status that sets a status based on which one is filled:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output would be all the data from above with one extra column for Status&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OBS &amp;nbsp; &amp;nbsp;...... &amp;nbsp; &amp;nbsp;status&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; open&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;act1&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;close&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In explaning the logic it would go:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If open_dt not null then status = 'open'&lt;/P&gt;
&lt;P&gt;if act1_dt not null then status = 'act1'&lt;/P&gt;
&lt;P&gt;if act2_dt not null then status = 'act2'&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if act3_dt not null then status = 'act3'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if act4_dt not null then status = 'act4'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if close_dt_dt not null then status = 'closed'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I feel like it would work like the above where it goes through them in order and just changes the status as it finds the next action.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am just not sure how to actual right this in SAS&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 22:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262226#M51147</guid>
      <dc:creator>Sotarkadin</dc:creator>
      <dc:date>2016-04-07T22:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variable based on reading data across the row.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262232#M51152</link>
      <description>&lt;P&gt;This works partially because the values you want are in the names of the variables and are separated by the _;&lt;/P&gt;
&lt;P&gt;The main part is the array and looping through it backwards. Note the order of variables on the ARRAY statement is important.&lt;/P&gt;
&lt;P&gt;The LEAVE statement says to stop looping when the first non-missing value is found. If there are no values for any of the _dt variables then status will be blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   informat account $6.;
   informat   open_dt act1_dt act2_dt act3_dt act4_dt close_dt mmddyy8.;
   format   open_dt act1_dt act2_dt act3_dt act4_dt close_dt mmddyy10.;
   input  Account open_dt act1_dt act2_dt act3_dt act4_dt close_dt;   
datalines;
123456  3/1/16    .        .          .         .     .
 23456  3/1/16    3/3/16   .          .         .     .
 34567  3/13/16   3/15/16   3/17/16    3/18/16  .     3/20/16
;
run;

data want;
   set have;
   length status $ 6;
   array dt open_dt act1_dt act2_dt act3_dt act4_dt close_dt;
   do i = dim(dt) to 1 by (-1);
      if not missing( dt[i] ) then do;
         status = scan(vname(dt[i]),1,'_');
         leave;
      end;
   end;
   drop i;
run;
 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Apr 2016 23:02:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262232#M51152</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-07T23:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variable based on reading data across the row.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262234#M51153</link>
      <description>&lt;P&gt;If you want to build that type of conditional logic you need to include the ELSE statements.&lt;/P&gt;
&lt;P&gt;IF A then action1; ELSE IF B then action2; ELSE IF C ....&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 23:05:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262234#M51153</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-04-07T23:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variable based on reading data across the row.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262326#M51177</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could I just add a small function I found recently that could help shrink the code somewhat. &amp;nbsp;I recently discovered that you can do a do loop over an array:&lt;/P&gt;
&lt;PRE&gt;data want;
  length status $6;
  set have;
  array dt close_dt act4_dt act3dt act2_dt act1_dt open_dt;
  do over dt;
    if not missing(dt) and missing(status) then status=scan(vname(dt),1,"_");
  end;
run;&lt;/PRE&gt;
&lt;P&gt;You will note that I have reversed the array setup to get the last in the list otherwise more or less the same, but without the incrementor. &amp;nbsp;Just wanted to point it out as the do over command is quite cool.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 08:17:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262326#M51177</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-08T08:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variable based on reading data across the row.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262331#M51179</link>
      <description>&lt;P&gt;Is the status determined by which variable has the latest date?&lt;/P&gt;
&lt;P&gt;If so then you can use functions like MAX() and WHICHN() to figure out which variable has the maximum value. &amp;nbsp;If you want to control which status wins when there is a tie for maximum date then set the order of the variables in the ARRAY statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  length account $6 status $6;
  informat open_dt act1_dt act2_dt act3_dt act4_dt close_dt mmddyy8.;
  format   open_dt act1_dt act2_dt act3_dt act4_dt close_dt yymmdd10.;
  input  Account open_dt act1_dt act2_dt act3_dt act4_dt close_dt;  
  array dt open_dt act1_dt act2_dt act3_dt act4_dt close_dt ;
  if n(of dt(*)) then status=upcase(scan(vname(dt(whichn(max(of dt(*)),of dt(*)))),1,'_'));
datalines;
Open  3/1/16    .        .          .         .     .
ACT1  3/1/16    3/3/16   .          .         .     .
CLOSE 3/13/16   3/15/16   3/17/16    3/18/16  .     3/20/16
TIE   3/13/16   3/15/16   3/16/16    3/16/16  .     . 
None . . . . . .
;

proc print; 
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2668iEDE0BC53F59FABB4/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 08:38:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262331#M51179</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-04-08T08:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variable based on reading data across the row.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262400#M51213</link>
      <description>&lt;P&gt;The status is not controlled by the date but by which action has a date. &amp;nbsp;Each of those actions could happen on the same date but they do happen in order. &amp;nbsp;It is opened, then act1, act2, etc.. until it's closed. &amp;nbsp;The last action to occur tells me where it is at in the process. &amp;nbsp;The close_dt is the last one as not all of the actions have to occur before it's closed. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 12:35:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262400#M51213</guid>
      <dc:creator>Sotarkadin</dc:creator>
      <dc:date>2016-04-08T12:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variable based on reading data across the row.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262426#M51220</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/3913"&gt;@Sotarkadin&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;The status is not controlled by the date but by which action has a date. &amp;nbsp;Each of those actions could happen on the same date but they do happen in order. &amp;nbsp;It is opened, then act1, act2, etc.. until it's closed. &amp;nbsp;The last action to occur tells me where it is at in the process. &amp;nbsp;The close_dt is the last one as not all of the actions have to occur before it's closed. &amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In that case the order of the variables in the array matter. So place them in decreasing order of status. So ties will go to the highest status. &amp;nbsp;closed,...act2,act1,opened.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 13:44:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262426#M51220</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-04-08T13:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variable based on reading data across the row.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262485#M51258</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will note that I have reversed the array setup to get the last in the list otherwise more or less the same, but without the incrementor. &amp;nbsp;Just wanted to point it out as the do over command is quite cool.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Quite cool, quite old, I learned it in SAS 5.1 &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And as any loop there are many ways. I picked one that directly (as close as I understand the problem) that would emulate the paper and pencil approach as simple to understand.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 15:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262485#M51258</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-08T15:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variable based on reading data across the row.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262514#M51272</link>
      <description>&lt;P&gt;Thanks for the replys all. &amp;nbsp;I am working on understanding the array. &amp;nbsp;It worked the first run through, I have one question/alteration. &amp;nbsp;There can be instances where all the dates are empty bc no action has been taking yet. &amp;nbsp;When this happened it returned the status as open since thats the first column it reads. &amp;nbsp;Is there a way for it to leave status blank if none of them have any dates?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 16:23:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262514#M51272</guid>
      <dc:creator>Sotarkadin</dc:creator>
      <dc:date>2016-04-08T16:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Variable based on reading data across the row.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262586#M51302</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/3913"&gt;@Sotarkadin&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the replys all. &amp;nbsp;I am working on understanding the array. &amp;nbsp;It worked the first run through, I have one question/alteration. &amp;nbsp;There can be instances where all the dates are empty bc no action has been taking yet. &amp;nbsp;When this happened it returned the status as open since thats the first column it reads. &amp;nbsp;Is there a way for it to leave status blank if none of them have any dates?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&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;The solution I posted leaves status blank when all of Open through close are missing.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 20:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Variable-based-on-reading-data-across-the-row/m-p/262586#M51302</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-08T20:12:21Z</dc:date>
    </item>
  </channel>
</rss>

