<?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: Convert to missing IF columns names date is greater then value in another col in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764238#M242047</link>
    <description>&lt;P&gt;But you should change the structure, so the calculations will be easier, and the final data set will be easier to work with.&lt;/P&gt;</description>
    <pubDate>Thu, 26 Aug 2021 15:12:38 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-08-26T15:12:38Z</dc:date>
    <item>
      <title>Convert to missing IF columns names date is greater then value in another col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764222#M242038</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;Please see a data base called have with columns: ID&amp;nbsp; ,month and follow up variables X2101-X2108&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Meaning of structure of X variables is year month&amp;nbsp; :YYMM).&lt;/P&gt;
&lt;P&gt;The meaning of month variable is the month the customer left the club.&lt;/P&gt;
&lt;P&gt;I want to create a new data set called wanted that will convert variables X's to missing&amp;nbsp; when the date of variable X is after month variable.&lt;/P&gt;
&lt;P&gt;So the expected data set is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ronein_0-1629988691476.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63054i3184DF63B90E85DD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ronein_0-1629988691476.png" alt="Ronein_0-1629988691476.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is way to do it using array or another method?&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;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Input ID month X2101 X2102 X2103 X2104 X2105 X2106 X2107 X2108;
Cards;
1 2106 10 20 30 40 50 60 70 80
2 .    40 20 20 80 50 70 70 90
3 2103 15 25 40 50 70 40 20 80
;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Aug 2021 14:39:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764222#M242038</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-08-26T14:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to missing IF columns names date is greater then value in another col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764229#M242040</link>
      <description>&lt;P&gt;Change your structure so that month information is not stored in the NAME of the variable.&lt;/P&gt;
&lt;P&gt;Either using PROC TRANSPOSE, or just read it in that way to start with.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID left @;
  do month=2101,2102,2103,2104,2105,2106,2107,2108;
    input value @;
    output;
  end;
cards;
1 2106 10 20 30 40 50 60 70 80
2 .    40 20 20 80 50 70 70 90
3 2103 15 25 40 50 70 40 20 80
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now detecting which values to "empty" is easy.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if . &amp;lt; left &amp;lt;= month then value=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to see a report in that tabular layout it is easy to do with the tall structure.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=want missing;
  column id left value,month;
  define id/group;
  define left/group;
  define value / min ' ' width=4;
  define month / across;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;                                            month


         ID       left  2101  2102  2103  2104  2105  2106  2107  2108
  --------------------------------------------------------------------
          1       2106    10    20    30    40    50     .     .     .
          2          .    40    20    20    80    50    70    70    90
          3       2103    15    25     .     .     .     .     .     .
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;You could even produce the report directly from the full data by using a WHERE clause.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report headline nocenter data=have missing;
  where not (. &amp;lt; left &amp;lt;=month) ;
  column id left value,month;
  define id/group;
  define left/group;
  define value / min ' ' width=4;
  define month / across;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Aug 2021 15:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764229#M242040</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-26T15:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to missing IF columns names date is greater then value in another col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764235#M242044</link>
      <description>Thank you,&lt;BR /&gt;However I ask not to change the source data set structure.&lt;BR /&gt;I recieve it as it is from external source and It consists millions of rows and many columns .&lt;BR /&gt;The question was how to perform the desired task wihtout changing the source data set.&lt;BR /&gt;It means that structure of data is wide (not long) and columns names are X2101,X2102....X2108&lt;BR /&gt;</description>
      <pubDate>Thu, 26 Aug 2021 15:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764235#M242044</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-08-26T15:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to missing IF columns names date is greater then value in another col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764238#M242047</link>
      <description>&lt;P&gt;But you should change the structure, so the calculations will be easier, and the final data set will be easier to work with.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 15:12:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764238#M242047</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-26T15:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to missing IF columns names date is greater then value in another col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764242#M242049</link>
      <description>&lt;P&gt;First thing, what about that missing month? Everything is greater than missing, so is "after".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming that missing months mean don't process this seems to work for the example data;&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  array x(*) X2101--X2108;
  if not missing (month) then do i=1 to dim(x);
     name=vname(x[i]);
     if index(name,put(month,4.))&amp;gt;0 then do j=i to dim(x);
        call missing(x[j]);
     end;
  end;
  drop i j name;
run;&lt;/PRE&gt;
&lt;P&gt;HOWEVER you have to increment the names of the variables in the array every time a column is added, the assumption is the columns will be adjacent.&lt;/P&gt;
&lt;P&gt;Caveat, your example desired output has the columns of the X variables in a different order and if that reflects your starting data the -- list operator may not work as expected. It is also very off-putting to have example data provided in a different order than the expected appearance as it is just a bit of a headache to read one set left to right and the other right to left.&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>Thu, 26 Aug 2021 15:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764242#M242049</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-26T15:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to missing IF columns names date is greater then value in another col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764293#M242065</link>
      <description>IF month value  is missing then it means that customer didnt leave and then we dont need to convert to missing</description>
      <pubDate>Thu, 26 Aug 2021 18:10:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764293#M242065</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-08-26T18:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to missing IF columns names date is greater then value in another col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764303#M242072</link>
      <description>&lt;P&gt;So if the variables of interest are the only ones that start with X you can use a variable list to define an array that automatically adjust to new columns.&amp;nbsp; If there are other variables whose name starts with X then you might have to hard code the list or at least use some other logic to calculate the list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array x x:;
  if not missing(month) then do i=1 to dim(x);
    if month &amp;lt;= input(substr(vname(x[i]),2),32.) then x[i]=.;
  end;
  drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Aug 2021 18:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764303#M242072</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-26T18:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: Convert to missing IF columns names date is greater then value in another col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764306#M242075</link>
      <description>&lt;P&gt;Transpose.&lt;/P&gt;
&lt;P&gt;Transpose.&lt;/P&gt;
&lt;P&gt;Transpose.&lt;/P&gt;
&lt;P&gt;Dates do not belong in column names.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 19:05:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-to-missing-IF-columns-names-date-is-greater-then-value/m-p/764306#M242075</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-26T19:05:15Z</dc:date>
    </item>
  </channel>
</rss>

