## first occurence of event within an array

Solved
Occasional Contributor
Posts: 18

# first occurence of event within an array

Hi,

I have hundred of varaibles in the data but for the illustration purppse I
reduce them to just 3 variables.
I want to capture the first occurence of "Y" for the observation within
the array named ADF(given below in the code and data)and record that
instance within the variable Def_month.
For expample in the data given below the first and second observation
experience "Y" in Dfm1,therefor Def_month variable should have 1.
While for the fourth and sixth observation the Def_moth should be 2 and
3.The code I have written gives errie results.

Data:-

Data I_have;
input Dfm1\$ Dfm2\$ Dfm3\$;
Datalines;
y y y
y N y
N N N
N y y
N N y
;
run;

code that I want to fix:-

Data I_get;
set I_have;
end;
run;

Result that I want to see:-

Data I_wanna;
input Dfm1\$ Dfm2\$ Dfm3\$ def_month;
Datalines;
y y y 1
y N y 1
N N N .
N y y 2
N N y 3
run;

Thanks in advance for any help.

Accepted Solutions
Solution
‎11-15-2011 03:16 PM
Super Contributor
Posts: 1,636

## Re: first occurence of event within an array

Data I_have;

input Dfm1\$ Dfm2\$ Dfm3\$;

def_month=find(catt(of dfm1-dfm3),'y');

if def_month=0 then def_month=.;

Datalines;

y y y

y N y

N N N

N y y

N N y

;

run;

All Replies
Solution
‎11-15-2011 03:16 PM
Super Contributor
Posts: 1,636

## Re: first occurence of event within an array

Data I_have;

input Dfm1\$ Dfm2\$ Dfm3\$;

def_month=find(catt(of dfm1-dfm3),'y');

if def_month=0 then def_month=.;

Datalines;

y y y

y N y

N N N

N y y

N N y

;

run;

🔒 This topic is solved and locked.