<?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: Output subsequent values when variable occurs the first time a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846163#M334522</link>
    <description>&lt;P&gt;sorry, I didn't understand your question. I was thinking of blanking all the&lt;STRONG&gt; first '4' values&lt;/STRONG&gt; not all the '4' values and outputting also the preceeding values&lt;/P&gt;</description>
    <pubDate>Thu, 24 Nov 2022 14:36:00 GMT</pubDate>
    <dc:creator>Anita_n</dc:creator>
    <dc:date>2022-11-24T14:36:00Z</dc:date>
    <item>
      <title>Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846134#M334500</link>
      <description>&lt;P&gt;Dear all, if I have a data that looks like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines;
input id var1 var2 var3 var4 $3.;
datalines;
1 4  3 2 5
2 2  4 5 6
3 4  6 7 8
4 8  4 2 5
5 6  1 0 10
6 10 1 4 5
7 4 5 6 4
8 1  4 6 4
9 5  5 9 10
10 4 9 4 4
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want each time the&amp;nbsp; value of var1=4 occurs&amp;nbsp; for the first time,&amp;nbsp; all values of subsequent variables to be outputted . e.g.&amp;nbsp; for id=1,&amp;nbsp; the output will be 3, 2, 5&lt;/P&gt;
&lt;P&gt;id=2, will be 5 and 6 etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 12:58:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846134#M334500</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-11-24T12:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846135#M334501</link>
      <description>&lt;P&gt;Outputted how? Can you post the form of your desired result?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 13:02:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846135#M334501</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-24T13:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846138#M334503</link>
      <description>&lt;P&gt;data want should look like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="415"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="82.7875px"&gt;id&amp;nbsp;&lt;/TD&gt;
&lt;TD width="82.8px"&gt;var1&lt;/TD&gt;
&lt;TD width="82.8px"&gt;var2&lt;/TD&gt;
&lt;TD width="82.8px"&gt;var3&lt;/TD&gt;
&lt;TD width="82.8125px"&gt;var4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82.7875px"&gt;1&lt;/TD&gt;
&lt;TD width="82.8px"&gt;4&lt;/TD&gt;
&lt;TD width="82.8px"&gt;3&lt;/TD&gt;
&lt;TD width="82.8px"&gt;2&lt;/TD&gt;
&lt;TD width="82.8125px"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82.7875px"&gt;2&lt;/TD&gt;
&lt;TD width="82.8px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="82.8px"&gt;4&lt;/TD&gt;
&lt;TD width="82.8px"&gt;5&lt;/TD&gt;
&lt;TD width="82.8125px"&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82.7875px"&gt;3&lt;/TD&gt;
&lt;TD width="82.8px"&gt;4&lt;/TD&gt;
&lt;TD width="82.8px"&gt;6&lt;/TD&gt;
&lt;TD width="82.8px"&gt;7&lt;/TD&gt;
&lt;TD width="82.8125px"&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82.7875px"&gt;4&lt;/TD&gt;
&lt;TD width="82.8px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="82.8px"&gt;4&lt;/TD&gt;
&lt;TD width="82.8px"&gt;2&lt;/TD&gt;
&lt;TD width="82.8125px"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82.7875px"&gt;6&lt;/TD&gt;
&lt;TD width="82.8px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="82.8px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="82.8px"&gt;4&lt;/TD&gt;
&lt;TD width="82.8125px"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82.7875px"&gt;7&lt;/TD&gt;
&lt;TD width="82.8px"&gt;4&lt;/TD&gt;
&lt;TD width="82.8px"&gt;5&lt;/TD&gt;
&lt;TD width="82.8px"&gt;6&lt;/TD&gt;
&lt;TD width="82.8125px"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82.7875px"&gt;8&lt;/TD&gt;
&lt;TD width="82.8px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="82.8px"&gt;4&lt;/TD&gt;
&lt;TD width="82.8px"&gt;6&lt;/TD&gt;
&lt;TD width="82.8125px"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82.7875px"&gt;10&lt;/TD&gt;
&lt;TD width="82.8px"&gt;4&lt;/TD&gt;
&lt;TD width="82.8px"&gt;9&lt;/TD&gt;
&lt;TD width="82.8px"&gt;4&lt;/TD&gt;
&lt;TD width="82.8125px"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 24 Nov 2022 13:26:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846138#M334503</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-11-24T13:26:32Z</dc:date>
    </item>
    <item>
      <title>Re: Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846139#M334504</link>
      <description>&lt;P&gt;Ok. Is var4 character and the other vars numeric intentionally?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 13:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846139#M334504</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-24T13:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846140#M334505</link>
      <description>&lt;P&gt;sorry, var1-var4 are characters only the id is numeric&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 13:32:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846140#M334505</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-11-24T13:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846141#M334506</link>
      <description>&lt;P&gt;Ok. Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines;
input id (var1 - var4)($);
datalines;
1 4  3 2 5
2 2  4 5 6
3 4  6 7 8
4 8  4 2 5
5 6  1 0 10
6 10 1 4 5
7 4 5 6 4
8 1  4 6 4
9 5  5 9 10
10 4 9 4 4
;
run;

data want(drop = flag);
   set have;
   array v $ var:;
   if '4' in v;

   do over v;
      if v = '4' then flag = 1;
      if flag = . then v = '';
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;id var1 var2 var3 var4
1  4    3    2    5
2       4    5    6
3  4    6    7    8
4       4    2    5
6            4    5
7  4    5    6    4
8       4    6    4
10 4    9    4    4&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Nov 2022 13:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846141#M334506</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-24T13:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846144#M334507</link>
      <description>&lt;P&gt;Thanks this was very fast,&amp;nbsp; will this also work if var were to be numeric?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 13:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846144#M334507</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-11-24T13:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846145#M334508</link>
      <description>&lt;P&gt;If they were all numeric, then yes, but of course, you would have to change '4' to 4 &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 13:49:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846145#M334508</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-24T13:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846146#M334509</link>
      <description>&lt;P&gt;yes, I tried that and it also worked, thanks&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 13:52:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846146#M334509</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-11-24T13:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846147#M334510</link>
      <description>&lt;P&gt;Anytime.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 13:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846147#M334510</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-24T13:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846152#M334514</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp; sorry I still need to ask this question for feature use. In case I need for this output not only the subsequent values but also the previous values how can I add this in the code?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 14:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846152#M334514</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-11-24T14:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846153#M334515</link>
      <description>&lt;P&gt;Meaning you want to blank all values besides the first one that is =4 / '4' ?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 14:10:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846153#M334515</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-24T14:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846161#M334520</link>
      <description>&lt;P&gt;meaning that I want in the output also the values&amp;nbsp; of the blanks to show.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and secondly, probably I wouldn't like to display the first occurence of 4 in the results&lt;/P&gt;
&lt;P&gt;it should then look like this:&lt;/P&gt;
&lt;P&gt;so that I can later concatenate easily;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="415"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="83"&gt;id&amp;nbsp;&lt;/TD&gt;
&lt;TD width="83"&gt;var1&lt;/TD&gt;
&lt;TD width="83"&gt;var2&lt;/TD&gt;
&lt;TD width="83"&gt;var3&lt;/TD&gt;
&lt;TD width="83"&gt;var4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;9&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 24 Nov 2022 14:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846161#M334520</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-11-24T14:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846162#M334521</link>
      <description>&lt;P&gt;This blanks simply all the '4' values?&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 14:28:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846162#M334521</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-24T14:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846163#M334522</link>
      <description>&lt;P&gt;sorry, I didn't understand your question. I was thinking of blanking all the&lt;STRONG&gt; first '4' values&lt;/STRONG&gt; not all the '4' values and outputting also the preceeding values&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 14:36:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846163#M334522</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-11-24T14:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: Output subsequent values when variable occurs the first time a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846414#M334617</link>
      <description>&lt;P&gt;This is my final solution&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=i);
set have;

array v(*) _character_ ;
if '4' in v;

do i=1 to dim(v);
  if v{i}='4' then do;
   v{i}= '';
   leave;
end;
end;

run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Nov 2022 14:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-subsequent-values-when-variable-occurs-the-first-time-a/m-p/846414#M334617</guid>
      <dc:creator>Anita_n</dc:creator>
      <dc:date>2022-11-26T14:46:33Z</dc:date>
    </item>
  </channel>
</rss>

