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

Hi, 

can you guys explain why the colon seems not to trim the dates before comparing and why I get more errors than warnings here?

 

data test;
input rfxstdtc $ 1-10 impdtc $ 12-21 usubjid $ 23-30;
cards;
2023-10-12 2023-11-12 DEU-001F
2023-10    2023-10-13 DEU-001F
2023       2023-10-14 DEU-001F
2023-11    2023-10-13 DEU-001F
run;
data test1;
   set test;
   if rfxstdtc^='' and impdtc^='' and rfxstdtc ^=: impdtc then put 'E' 'RROR:# Imputation occurred on different partials dates ' _N_= USUBJID= rfxstdtc= impdtc= ; 
   if rfxstdtc^='' and impdtc^='' and strip(rfxstdtc) ^=: strip(impdtc) then put 'W' 'ARNING:# Imputation occurred on different partials dates ' _N_= USUBJID= rfxstdtc= impdtc= ; 
run;
________________________

- Cheers -

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @Oligolas,

 

The comparison is restricted to the length of the shorter string, including trailing blanks, if any.

Example:

436   data _null_;
437   if 'AB' =:'ABC'  then put 'true1';
438   if 'AB '=:'ABC'  then put 'false';
439   if 'AB '=:'AB C' then put 'true2';
440   run;

true1
true2

The first comparison looks at two characters, the second and third comparison include three.

 

Your rfxstdtc and impdtc values contain ten characters since 10 is the defined length of both variables, so the comparisons without STRIP (or TRIM) are based on all ten characters. The expressions returned by the STRIP function are shorter if (leading or) trailing blanks were present in the arguments, so the comparisons change correspondingly.

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Explain, please. What is wrong with the results in the log? What is the expected result?

--
Paige Miller
Oligolas
Barite | Level 11

@PaigeMiller I obviously took a statement in a paper 'as is' without checking it's validity or I simply misunderstood it

 

"These operators compare two strings after making the strings the same length by truncating the longer string to the same length as the shorter string."

________________________

- Cheers -

FreelanceReinh
Jade | Level 19

Hi @Oligolas,

 

The comparison is restricted to the length of the shorter string, including trailing blanks, if any.

Example:

436   data _null_;
437   if 'AB' =:'ABC'  then put 'true1';
438   if 'AB '=:'ABC'  then put 'false';
439   if 'AB '=:'AB C' then put 'true2';
440   run;

true1
true2

The first comparison looks at two characters, the second and third comparison include three.

 

Your rfxstdtc and impdtc values contain ten characters since 10 is the defined length of both variables, so the comparisons without STRIP (or TRIM) are based on all ten characters. The expressions returned by the STRIP function are shorter if (leading or) trailing blanks were present in the arguments, so the comparisons change correspondingly.

Tom
Super User Tom
Super User

Why would you use STRIP() instead of TRIM()?

Do you expect the values to have leading spaces?  And if so why do you want to remove the leading spaces?

Oligolas
Barite | Level 11

Hi @Tom I do not 'expect' it, I only use strip as a standard to compare strings

________________________

- Cheers -

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!

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