data Have;
input col1 $ col2 $ col3 $ col4 $ col5 $ col6 $ col7 $ col8 $ col9 $ col10 $;
cards;
PM MM JM MM PM PB . . PM .
PM MM JM MM PM PB JM . . .
PM MM JM MM PM MB PM MM . .
PM MM JM MM PM PM MM MB . .
PM MM JM MM PM PM MM PB . .
;
Hello all, I was not clear in my details and goal in my last post. So, I am reposting this again.
The data look like what I have in 'Have' above.
Want:
I need to find and flag records that have any value occurring after 'PB' or 'MB', if there is any non-missing value occurring after values 'PB' or 'MB' horizontally, I want to flag it.
flag
PM MM JM MM PM PB . . PM . 1
PM MM JM MM PM PB JM . . . 1
PM MM JM MM PM MB PM MM . . 1
PM MM JM MM PM PM MM MB . 0
PM MM JM MM PM PM MM PB . 0
Thank you for your time on this.
I below giving you the desired outcome?
data have;
infile datalines truncover;
input col1 $ col2 $ col3 $ col4 $ col5 $ col6 $ col7 $ col8 $ col9 $ col10 $;
datalines;
PM MM JM MM PM PB . . PM .
PM MM JM MM PM PB JM . . .
PM MM JM MM PM MB PM MM . .
PM MM JM MM PM PM MM MB . .
PM MM JM MM PM PM MM PB . .
PB MB
MM JM MM PM PM MM
PM MM JM MM PM PM MM MM . PB
MM MM MM MM PM PM MM MM MM MM
;
data new(drop=_:);
set have;
array _cols {*} col:;
flag=0;
_flag=0;
do _i=dim(_cols) to 1 by -1;
if _cols[_i] in ('MB','PB') then
do;
flag=_flag;
leave;
end;
if not missing(_cols[_i]) and _cols[_i] not in ('MB','PB') then _flag=1;
end;
run;
proc print;
run;
I below giving you the desired outcome?
data have;
infile datalines truncover;
input col1 $ col2 $ col3 $ col4 $ col5 $ col6 $ col7 $ col8 $ col9 $ col10 $;
datalines;
PM MM JM MM PM PB . . PM .
PM MM JM MM PM PB JM . . .
PM MM JM MM PM MB PM MM . .
PM MM JM MM PM PM MM MB . .
PM MM JM MM PM PM MM PB . .
PB MB
MM JM MM PM PM MM
PM MM JM MM PM PM MM MM . PB
MM MM MM MM PM PM MM MM MM MM
;
data new(drop=_:);
set have;
array _cols {*} col:;
flag=0;
_flag=0;
do _i=dim(_cols) to 1 by -1;
if _cols[_i] in ('MB','PB') then
do;
flag=_flag;
leave;
end;
if not missing(_cols[_i]) and _cols[_i] not in ('MB','PB') then _flag=1;
end;
run;
proc print;
run;
Yes, this works. Thank you @Patrick
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!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: