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. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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