🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 07-09-2020 03:31 PM
(1157 views)
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
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Add a "??" before the informat name :
input(strip(trim(substr(TextTerm,7,6))), ?? 8.)
:
PG
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;