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

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
PaigeMiller
Diamond | Level 26
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

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26
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
yabwon
Amethyst | Level 16

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

_______________
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



Ronein
Onyx | Level 15

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;
yabwon
Amethyst | Level 16

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



How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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