Hi....I am looking for a way to avoid the warning messages as I do recognize that they are due to having both numeric and character strings when the substr is executed. If the string is all numbers, then Division is blank otherwise Division is equal to the string. I am wondering if there is a more efficient way to achieve the same results....Thanks
data have; length TextTerm $ 12 ; format TextTerm $CHAR12. ; informat TextTerm $CHAR12. ; infile datalines4 dlm='7F'x missover dsd; input TextTerm : $CHAR12. ; datalines4; 13-14 Trm 1C 14-15 Cohort 14-15 Con Ed 19-20 C 19-20 CH 19-20 ESL 2019-2020 2020-2021 19-20 ESLQ ;;;; data Want; length Division $20.; set Have; if input(strip(trim(substr(TextTerm,7,6))),8.)>0 then Division = ' '; else Division = strip(trim(substr(TextTerm,7,6))); run; Warning Message: NOTE: Invalid argument to function INPUT at line 51 column 6. Division=Trm 1C TextTerm=13-14 Trm 1C _ERROR_=1 _N_=1 NOTE: Invalid argument to function INPUT at line 51 column 6. Division=Cohort TextTerm=14-15 Cohort _ERROR_=1 _N_=2
data have;
length TextTerm $ 12 ;
format TextTerm $CHAR12. ;
informat TextTerm $CHAR12. ;
infile datalines4 dlm='7F'x missover dsd;
input TextTerm : $CHAR12. ;
datalines4;
13-14 Trm 1C
14-15 Cohort
14-15 Con Ed
19-20 C
19-20 CH
19-20 ESL
2019-2020
2020-2021
19-20 ESLQ
;;;;
data Want;
length Division $20.;
set Have;
if not notdigit(strip(substr(TextTerm,7,6))) then
Division = ' ';
else
Division = strip(trim(substr(TextTerm,7,6)));
run;
Add a "??" before the informat name :
input(strip(trim(substr(TextTerm,7,6))), ?? 8.)
:
data have;
length TextTerm $ 12 ;
format TextTerm $CHAR12. ;
informat TextTerm $CHAR12. ;
infile datalines4 dlm='7F'x missover dsd;
input TextTerm : $CHAR12. ;
datalines4;
13-14 Trm 1C
14-15 Cohort
14-15 Con Ed
19-20 C
19-20 CH
19-20 ESL
2019-2020
2020-2021
19-20 ESLQ
;;;;
data Want;
length Division $20.;
set Have;
if not notdigit(strip(substr(TextTerm,7,6))) then
Division = ' ';
else
Division = strip(trim(substr(TextTerm,7,6)));
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.