Why are you only doing the operations until the FOLHA=5?
data base1;
set base;
if segmento_final ~= "varejo classic" and qtde_parcela < 6.5 then folha = 1;
else if segmento_final ~= "varejo classic" and 6.5 <= qtde_parcela < 18.5 then folha = 2;
else if segmento_final ~= "varejo classic" and 18.5 <= qtde_parcela and escore_348 < 230 then folha = 3;
else if segmento_final ~= "varejo classic" and 18.5 <= qtde_parcela and 230 <= escore_348 < 320.5 then folha = 4;
else if segmento_final ~= "varejo classic" and 18.5 <= qtde_parcela and 320.5 <= escore_348 then folha = 5;
else if segmento_final = "varejo classic" and 6.5 > qtde_parcela and 130.5 > escore_348 then folha = 6;
else if segmento_final = "varejo classic" and 6.5 > qtde_parcela and 130.5 <= escore_348 < 255.5 then folha = 7;
else if segmento_final = "varejo classic" and 6.5 > qtde_parcela and escore_348 >= 255.5 then folha = 8;
else if segmento_final = "varejo classic" and 6.5 <= qtde_parcela < 18.5 and escore_348 < 157.5 then folha = 9;
else if segmento_final = "varejo classic" and 6.5 <= qtde_parcela < 18.5 and 157.5 <= escore_348 < 267.5 then folha = 10;
else if segmento_final = "varejo classic" and 6.5 <= qtde_parcela < 18.5 and 267.5 <= escore_348 then folha = 11;
else if segmento_final = "varejo classic" and 18.5 <= qtde_parcela and escore_348 < 172.5 then folha = 12;
else if segmento_final = "varejo classic" and 18.5 <= qtde_parcela and 172.5 <= escore_348 < 295.5 then folha = 13;
else folha = 14;
run;
@Thalitacosta wrote:
Why are you only doing the operations until the FOLHA=5?
data base1;
set base;
if segmento_final ~= "varejo classic" and qtde_parcela < 6.5 then folha = 1;
else if segmento_final ~= "varejo classic" and 6.5 <= qtde_parcela < 18.5 then folha = 2;
else if segmento_final ~= "varejo classic" and 18.5 <= qtde_parcela and escore_348 < 230 then folha = 3;
else if segmento_final ~= "varejo classic" and 18.5 <= qtde_parcela and 230 <= escore_348 < 320.5 then folha = 4;
else if segmento_final ~= "varejo classic" and 18.5 <= qtde_parcela and 320.5 <= escore_348 then folha = 5;
else if segmento_final = "varejo classic" and 6.5 > qtde_parcela and 130.5 > escore_348 then folha = 6;
else if segmento_final = "varejo classic" and 6.5 > qtde_parcela and 130.5 <= escore_348 < 255.5 then folha = 7;
else if segmento_final = "varejo classic" and 6.5 > qtde_parcela and escore_348 >= 255.5 then folha = 8;
else if segmento_final = "varejo classic" and 6.5 <= qtde_parcela < 18.5 and escore_348 < 157.5 then folha = 9;
else if segmento_final = "varejo classic" and 6.5 <= qtde_parcela < 18.5 and 157.5 <= escore_348 < 267.5 then folha = 10;
else if segmento_final = "varejo classic" and 6.5 <= qtde_parcela < 18.5 and 267.5 <= escore_348 then folha = 11;
else if segmento_final = "varejo classic" and 18.5 <= qtde_parcela and escore_348 < 172.5 then folha = 12;
else if segmento_final = "varejo classic" and 18.5 <= qtde_parcela and 172.5 <= escore_348 < 295.5 then folha = 13;
else folha = 14;
run;
Do you mean to ask why your code is not generating any values of FOLHA larger than 5? The "Why are you only doing the operations " does not really tell us who the "you" are asking might be.
I use code like to check the inputs and results of recoding:
proc freq data=base1; tables segmento_final* folha * qtde_parcela * escore_348 \ missing list nocum nopercent; run;
This will generate a relatively easy to read table of results and which value combinations were assigned.
Note that very likely issue is the spelling for the Segmento_final variable. If the value is never exactly "varejo classic" then all the results would be in the first 5 value or possibly 14.
1. The first thing I would do is to use the LOWCASE() function so that capitalization doesn't matter All of these would be matches:
"varejo classic"
"Varejo Classic"
"VAREJO CLASSIC"
@ballardw's advice is sound, and you should follow it, but LOWCASE() is something that will correct one of the most common problems.
2. Since everything is either "varejo classic" or it is not, break your logic into two parts rather than coding "varejo classic" over and over again.
Something like this:
data base1;
set base;
IF LOWCASE(Segmento_Final) = "varejo classic" THEN
DO;
/* code for "varejo classic" goes here */
END;
ELSE
DO;
/* code for NOT "varejo classic" goes here */
END;
3. Make sure you always have an "else" condition. What happens if none of the conditions are fully met? Should the value be missing? Should a default be assigned?
Jim
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.