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;
array ADF{*}$ dfm1-dfm3;
do i=1 to dim(ADF);
if ADF(i) ="y" then def_month=i;
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.
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;
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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.