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;
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;
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;
Hi,
how about:
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
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;
Hi,
I did small update 🙂
Bart
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.
Ready to level-up your skills? Choose your own adventure.