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

Hello.

  I am trying to merge two variables by replacing the word OTHERcin one column with the content of another column. I am using the code below, but I have 3-4 cells that are blank (They didn't merge both columns). I can't seem to figure out what's the problem with those specific cells.

 

DATA WANT(RENAME=(AFORF2=AFORF_H_OF1));; /*THE NEW RISK HISTORY COLUMN IS AFORF_H_OF1*/
set HAVE;
if index(upcase(AFORF_H_OF),'OTHER') THEN
DO ;
AFORF1=cats(TRANSTRN(AFORF_H_OF,"Other",trimn('')),'|',Risk_H);;
AFORF2=TRANWRD(AFORF1,'||','|');
END;
ELSE AFORF2=AFORF_H_OF;
DROP AFORF1;

if index(upcase(AFORF_C_PREGN1),'OTHER') THEN
DO ;
AFORF_C1=cats(TRANSTRN(AFORF_C_PREGN1,"Other",trimn('')),'|',C_Risks);;
AFORF_C2=TRANWRD(AFORF_C1,'||','|');
END;
ELSE AFORF_C2=AFORF_C_PREGN1;/*THE NEW CURRENT RISKS COLUMN IS AFORF_C2*/
DROP AFORF_C1;
RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Did you verify that values of AFORF1 and AFORF_C1 were as expected before dropping them?

 

How long are the values of AFORF_H_OF, Risk_h , AFORF_C_PREGN1 and C_risks ?

 

If the pieces are long enough then your use of CATS may be truncating because you have not defined a length of the variables AFORF1 and AFORF_C1 which means they default to maximum of 200 characters. So it might appear that they aren't concatenating because you didn't allow room in the resulting variable to hold the values. The AFORF2 and AFORF_C2 would inherit the lengths of the base variables.

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Can we see a small portion of the actual data set that illustrates the problem? Please provide the data as working SAS data step code, and not via any other method. (Instructions and examples).

--
Paige Miller
PaigeMiller
Diamond | Level 26

I asked to see a portion of the data, and gave instructions how to provide it.

--
Paige Miller
ballardw
Super User

Did you verify that values of AFORF1 and AFORF_C1 were as expected before dropping them?

 

How long are the values of AFORF_H_OF, Risk_h , AFORF_C_PREGN1 and C_risks ?

 

If the pieces are long enough then your use of CATS may be truncating because you have not defined a length of the variables AFORF1 and AFORF_C1 which means they default to maximum of 200 characters. So it might appear that they aren't concatenating because you didn't allow room in the resulting variable to hold the values. The AFORF2 and AFORF_C2 would inherit the lengths of the base variables.

bn820
Obsidian | Level 7

Thank you! I defined the length of AFORF1, and it worked. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 5 replies
  • 1246 views
  • 0 likes
  • 3 in conversation