<?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: Finding first occurence in a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645511#M192993</link>
    <description>&lt;P&gt;Of course we can solve this with the original structure, but compare your array code with this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set long (where=(value &amp;gt;= 100));
by id;
if first.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Maxim 33: Intelligent Data Makes for Intelligent Programs, and I take every opportunity to show newbies how to properly design data.&lt;/P&gt;</description>
    <pubDate>Wed, 06 May 2020 04:44:19 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-05-06T04:44:19Z</dc:date>
    <item>
      <title>Finding first occurence in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645140#M192800</link>
      <description>&lt;P&gt;Hi. I have a data set like below. I need to find the date where the first occurrence of 100 occurs for a ID. Keep the counter as 1. Transpose is not working. So couldn't use&amp;nbsp; first. and last. Its a huge dataset. Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Id&lt;/TD&gt;&lt;TD&gt;30-Apr-18&lt;/TD&gt;&lt;TD&gt;31-May-18&lt;/TD&gt;&lt;TD&gt;30-Jun-18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;120&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;75&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;89&lt;/TD&gt;&lt;TD&gt;90&lt;/TD&gt;&lt;TD&gt;120&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 05 May 2020 01:34:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645140#M192800</guid>
      <dc:creator>Sandy10</dc:creator>
      <dc:date>2020-05-05T01:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first occurence in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645141#M192801</link>
      <description>&lt;P&gt;Please take a look at&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;STRONG&gt;wHICHN/CHOOSEN&lt;/STRONG&gt;&amp;nbsp;group of Functions.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 01:47:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645141#M192801</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-05T01:47:44Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first occurence in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645165#M192824</link>
      <description>&lt;P&gt;Guess that might not give wat I wnat. It counts from backwards oif there is a negative value. I don want that. The table do have negative value.&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 04:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645165#M192824</guid>
      <dc:creator>Sandy10</dc:creator>
      <dc:date>2020-05-05T04:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first occurence in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645166#M192825</link>
      <description>&lt;P&gt;Please present your data as a sas data step.&amp;nbsp; It looks like you have variables named '30-Apr-18'n, '31-May-18'n, and '30-Jun-18'n. &amp;nbsp; Possible but extremely unlikely.&amp;nbsp; So show us what it actually looks like - help us help you.&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 04:57:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645166#M192825</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-05-05T04:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first occurence in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645175#M192832</link>
      <description>&lt;P&gt;Transpose works for me, see:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;

data have;
input Id $ '30-Apr-18'n '31-May-18'n '30-Jun-18'n;
datalines;
1 120 100 200
2 50 200 75
3 89 90 120
;

proc transpose data=have out=trans;
by id;
var _numeric_;
run;

data long;
set trans;
date = input(_name_,date9.);
format date yymmddd10.;
drop _name_;
rename col1=value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Define what you see as "huge". Be precise in numbers: number of observations, number of variables, observation size.&lt;/P&gt;
&lt;P&gt;Also post what you expect as a result. Do you only want to keep certain observations, do you want to set a variable, what if a value of 100 does not appear for a certain id; what do you mean by "keep counter as 1"?&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 06:36:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645175#M192832</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-05T06:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first occurence in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645186#M192835</link>
      <description>Hi Kurt. Thansk for yoiur reply. I require below output: basically retireve date valuw where first occurence occured.&lt;BR /&gt;&lt;BR /&gt;ID firstoccurenceofmorethan100&lt;BR /&gt;1 30apr2018&lt;BR /&gt;2 31may2018&lt;BR /&gt;3 30jun2018&lt;BR /&gt;</description>
      <pubDate>Tue, 05 May 2020 07:41:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645186#M192835</guid>
      <dc:creator>Sandy10</dc:creator>
      <dc:date>2020-05-05T07:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first occurence in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645188#M192836</link>
      <description>&lt;P&gt;Add this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set long;
by id date;
where value&amp;gt;100;
if not first.id then delete;
drop value;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 May 2020 07:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645188#M192836</guid>
      <dc:creator>sustagens</dc:creator>
      <dc:date>2020-05-05T07:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first occurence in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645189#M192837</link>
      <description>&lt;P&gt;Another example what I mean by "being precise":&lt;/P&gt;
&lt;P&gt;in your initial post, you asked for "&lt;SPAN&gt;the date where the first occurrence of 100 occurs", but now you name your new variable "firstoccurenceofmorethan100", so you are looking for 100 or greater, and not just exactly 100; this is substantial information!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So now we have to add a sort (just to be sure) and a data step that does the selection:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;

data have;
input Id $ '30-Apr-18'n '31-May-18'n '30-Jun-18'n;
datalines;
1 120 100 200
2 50 200 75
3 89 90 120
;

proc transpose data=have out=trans;
by id;
var _numeric_;
run;

data long;
set trans;
date = input(_name_,date9.);
format date yymmddd10.;
drop _name_;
rename col1=value;
run;

proc sort data=long;
by id date;
run;

data want;
set long (where=(value &amp;gt;= 100));
by id;
if first.id;
run;

proc print data=want noobs;
var id date value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Result:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;Id	date	value
1	2018-04-30	120
2	2018-05-31	200
3	2018-06-30	120
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;FONT size="2"&gt;Edit: complete code (original post had old contents of clipboard).&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 08:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645189#M192837</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-05T08:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first occurence in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645503#M192989</link>
      <description>&lt;P&gt;I don't think I see the need for a proc transpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Each ID has only one observation (i.e. one row with some number of dates)&lt;/LI&gt;
&lt;LI&gt;The variable names that represent dates are already in chronological order&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;then I think it should be a single data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;
data have;
input Id $ '30-Apr-18'n '31-May-18'n '30-Jun-18'n;
datalines;
1 120 100 200
2 50 200 75
3 89 90 120
4  1  2   3
;

data want (keep=id date value);
  set have ;
  array dts {*} _numeric_;
  do i=1 to dim(dts) until (value&amp;gt;=100);
    value=dts{i};
  end;
  if i&amp;gt;dim(dts) then value =.;
  else date=input(vname(dts{i}),date9.);
  format date date9.;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This program also assumes that the only numeric variables are the ones whose names represent dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also I put in a 4th row with no qualifying values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2020 03:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645503#M192989</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-05-06T03:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first occurence in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645507#M192992</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&lt;SPAN&gt;&amp;nbsp;the first occurrence of 100&amp;nbsp;&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;Guess that might not give wat I wnat.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Guess you didn't look properly or explain your problem properly.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;'s solution solves your need.&lt;/P&gt;
&lt;P&gt;Also please check your typos (I make many typos too, so I feel free to mention that!).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Reading further, you did indeed misrepresent your problem.&lt;/P&gt;
&lt;P&gt;Please try to avoid that to save everyone's time. Especially your helpers' time.&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2020 04:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645507#M192992</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-05-06T04:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: Finding first occurence in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645511#M192993</link>
      <description>&lt;P&gt;Of course we can solve this with the original structure, but compare your array code with this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set long (where=(value &amp;gt;= 100));
by id;
if first.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Maxim 33: Intelligent Data Makes for Intelligent Programs, and I take every opportunity to show newbies how to properly design data.&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2020 04:44:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-first-occurence-in-a-dataset/m-p/645511#M192993</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-06T04:44:19Z</dc:date>
    </item>
  </channel>
</rss>

