BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Swordfish
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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;

View solution in original post

1 REPLY 1
Linlin
Lapis Lazuli | Level 10

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1037 views
  • 0 likes
  • 2 in conversation