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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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