Hello. I have done some simple basic recodes that look like this:
But after checking the initial variable REF_COMP_1ST crossed with the recoded variable, it seems that my codes only went until 9.
Why is this happening? The recodes went until 9 and then assigned 1 to all the other values.
Both of the variables are CHAR. I have tried switching the _REC variable to NUMERIC but I had the same outcome.
Thanks for helping! 🙂
You need to assign a length of 2 (that's two characters) to the variable REF_COMP_1st_REC
length REF_COMP_1st_REC $ 2;
Otherwise, SAS uses the length of the variable the first time it is assigned, which is one character.
Which brings up the question ... why do you need to do any such recoding? Why do this work in the first place? How is a value of '10' more useful than a value of 'AOSTA-EMILIA-SICILIA-PERU DECAF'?? What can you do with '10' that you can't do with AOSTA-EMILIA-SICILIA-PERU DECAF'??
You need to assign a length of 2 (that's two characters) to the variable REF_COMP_1st_REC
length REF_COMP_1st_REC $ 2;
Otherwise, SAS uses the length of the variable the first time it is assigned, which is one character.
Which brings up the question ... why do you need to do any such recoding? Why do this work in the first place? How is a value of '10' more useful than a value of 'AOSTA-EMILIA-SICILIA-PERU DECAF'?? What can you do with '10' that you can't do with AOSTA-EMILIA-SICILIA-PERU DECAF'??
Thank you very much! You saved me. 🤗
Trust me, I wanted to leave the variable as it was, with the long labels and everything, but sometimes, these variables will be used in other programs, and having codes instead of labels will be easier.
@Diana123 wrote:
Thank you very much! You saved me. 🤗
Trust me, I wanted to leave the variable as it was, with the long labels and everything, but sometimes, these variables will be used in other programs, and having codes instead of labels will be easier.
Why not make the recodes numbers instead of character strings? Numbers will be easier to type, and will sort properly.
I totally agree with you, but I kinda "inherited" this whole script that is made a long time ago. I will try in the future to try to make it more efficient. Again, I really appreciate your help.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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: