BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mariko5797
Pyrite | Level 9

I want AVISIT to be proper case while maintaining all caps for my abbreviations.

My attempt is yielding inconsistent outcomes...

 

data have;
 length visit $22.;
 input visit $20.;
 cards;
 INITIAL SCREENING
 MOCK CHMI DAY 1
 MOCK CHMI DAY 21
 CHMI1 DAY 1
 CHMI1 DAY 2
 CHMI2 DAY 1
 CHMI3 DAY 1
 CHMI3 DAY 8
 CHMI3 DAY 12
 ;
run;

data want;
 length visit $22.;
 input visit $20.;
 cards;
 Initial Screening
 Mock CHMI Day 1
 MOCK CHMI Day 21
 CHMI 1 Day 1
 CHMI 1 Day 2
 CHMI 2 Day 1
 CHMI 3 Day 1
 CHMI 3 Day 8
 CHMI 3 Day 12
 ;
run;

My attempt:

data test;
 set have;
 avisit_ = propcase(visit);
 avisit = translate(avisit_, 'Chmi', 'CHMI ');
run;

Outcome:

mariko5797_0-1641307230379.png

I initially attempted this code with more variables within a dataset and ended up with an empty column and this in the log file (the 'Note' repeated). VISIT format and informat are both characters, I don't quite understand why it is converting to numeric. The 'Note: Invalid numeric data...' is also not consistently written with each run, but I still get the conversion notes.

581  data test0;
582   set _work00_;
583      avisit = propcase(visit);
584      avisit = translate(avisit, 'Chmi', 'CHMI');
585      avisitn = visitnum;
586      *if avisit = 'Max Severity Post Baseline' then avisitn = 999;
587      ***;
588      atptn = scan(avisit, -1);
589      if find(avisit, 'Unscheduled') > 0 then atptn = scan(avisitn, 2);
590      if find(avisit, 'Screening') > 0 then atptn = 0.1;
591      if find(vstpt, 'POST MOCK') > 0 then atptn = 1.1;
592      if find(avisit, '28 Days After') > 0 then atptn = 28;
593      atpt = 'Day '||strip(atptn);
594
595      keep usubjid visit visitnum avisit avisitn vstpt atptn atpt;
596  run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      583:14   584:14
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      584:24   588:18   589:13   589:58   590:13   590:51   591:50   592:13   592:55
NOTE: Invalid numeric data, 'Initial Screening' , at line 583 column 14.
NOTE: Invalid numeric data, 'Mock Chmi Day 1' , at line 583 column 14.

Does anyone have any ideas? Thank you in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You do not want the TRANSLATE function in this sort of assignment. Translate changes character by character in the parameter lists. ALL 'M' become 'm' with your example. Note that the first parameter in Translate is the "to value list" and the second parameter is the "from value list". You wouldn't be the first person to confuse which order you want the parameters.

 

584      avisit = translate(avisit, 'Chmi', 'CHMI');

 

You likely want the TRANWRD function which changes a group of characters for an entire different group, and the "from value" is the first parameter and the "to value" is the second parameter.

avisit = tranwrd(avisit,'Chmi','CHMI');

 

If your "word" is possibly part of another word where you wouldn't want to change it you may need considerably more logic.

View solution in original post

2 REPLIES 2
yabwon
Onyx | Level 15
data test;
 set have;
 avisit_ = propcase(visit);
 avisit = tranwrd(avisit_, 'Chmi', 'CHMI ');
run;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



ballardw
Super User

You do not want the TRANSLATE function in this sort of assignment. Translate changes character by character in the parameter lists. ALL 'M' become 'm' with your example. Note that the first parameter in Translate is the "to value list" and the second parameter is the "from value list". You wouldn't be the first person to confuse which order you want the parameters.

 

584      avisit = translate(avisit, 'Chmi', 'CHMI');

 

You likely want the TRANWRD function which changes a group of characters for an entire different group, and the "from value" is the first parameter and the "to value" is the second parameter.

avisit = tranwrd(avisit,'Chmi','CHMI');

 

If your "word" is possibly part of another word where you wouldn't want to change it you may need considerably more logic.

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