Meteorite | Level 14

## If fail then convert to missing all scores after failure time

Hello

I have for each customer  score information for each month since joining the population.

Score is between 1 to 10 (score 10 is when customer fail).

I want to convert  all scores to missing after customer received failure score.

In the real data there are many score fields and I want to ask if there is a more clever way to write:

IF g1=10 then do; g2=.;g3=;g4=.;g5=;.g6=.;end;
IF g2=10 then do;g3=;g4=.;g5=.;g6=.;end;
IF g3=10 then do;g4=.;g5=.;g6=.;end;
IF g4=10 then do;g5=.;g6=.;end;
IF g5=10 then do;g6=.;end;

``````Data  tbl1;
INPUT ID  g1 g2 g3 g4 g5 g6;
cards;
1 7 7 8 9 7 8
2 4 5 5 6 7 7
3 9 10 10 10 10 10
4 7 9 10 10 10 9
5 3 4 4 4 4 3
;
run;

Data tbl2;
SET tbl1;
IF g1=10 then do; g2=.;g3=;g4=.;g5=;.g6=.;end;
IF g2=10 then do;g3=;g4=.;g5=.;g6=.;end;
IF g3=10 then do;g4=.;g5=.;g6=.;end;
IF g4=10 then do;g5=.;g6=.;end;
IF g5=10 then do;g6=.;end;
Run;

``````
1 ACCEPTED SOLUTION

Accepted Solutions
Diamond | Level 26

## Re: I fail then convert to missing all scores after

``````Data  tbl1;
INPUT ID  g1 g2 g3 g4 g5 g6;
array g g1-g6;
do i=1 to 6;
if g(i)=10 and i<6 then do j=(i+1) to 6;
g(j)=.;
end;
end;
cards;
1 7 7 8 9 7 8
2 4 5 5 6 7 7
3 9 10 10 10 10 10
4 7 9 10 10 10 9
5 3 4 4 4 4 3
;
run;``````
--
Paige Miller
4 REPLIES 4
Diamond | Level 26

## Re: I fail then convert to missing all scores after

``````Data  tbl1;
INPUT ID  g1 g2 g3 g4 g5 g6;
array g g1-g6;
do i=1 to 6;
if g(i)=10 and i<6 then do j=(i+1) to 6;
g(j)=.;
end;
end;
cards;
1 7 7 8 9 7 8
2 4 5 5 6 7 7
3 9 10 10 10 10 10
4 7 9 10 10 10 9
5 3 4 4 4 4 3
;
run;``````
--
Paige Miller
Onyx | Level 15

## Re: If fail then convert to missing all scores after failure time

Hi,

``````Data tbl2;
SET tbl1;
array G g:;
_N_ = .;
do over G;
if _N_ = 10 then  G  = .;
else _N_ = max(G,_N_);
end;
Run;``````

All the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation

Meteorite | Level 14

## Re: If fail then convert to missing all scores after failure time

Great,

``````Data tbl1;
input ID gk1 gk2 gk3 gk4 gk5 gk6;
cards;
1 7 7 8 9 7 8
2 4 5 5 6 7 7
3 9 10 10 10 10 10
4 7 9 10 10 10 9
5 3 4 4 4 4 3
;
run;

Data tbl2;
set tbl1;
array _b(*) gk1-gk6;
do i=1 to 6;
do j=i+1 to 6;
if _b(i)=10 then _b(j)=.;
drop i j;
end;
end;
Run;``````
Onyx | Level 15

## Re: If fail then convert to missing all scores after failure time

Hi,

I did small update 🙂

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation

Discussion stats
• 4 replies
• 589 views
• 2 likes
• 3 in conversation