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 -
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.
Explain, please. What is wrong with the results in the log? What is the expected result?
@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 -
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.
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?
Hi @Tom I do not 'expect' it, I only use strip as a standard to compare strings
- Cheers -
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.