BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Diana123
Calcite | Level 5

Hello. I have done some simple basic recodes that look like this:

Diana123_0-1700050148382.png

But after checking the initial variable REF_COMP_1ST crossed with the recoded variable, it seems that my codes only went until 9.

Diana123_1-1700050196241.png

Diana123_2-1700050212111.png

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! 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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'??

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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'??

--
Paige Miller
Diana123
Calcite | Level 5

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. 

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
Diana123
Calcite | Level 5

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 488 views
  • 0 likes
  • 2 in conversation