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

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
smantha
Lapis Lazuli | Level 10
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;

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

Add a "??" before the informat name :

 

input(strip(trim(substr(TextTerm,7,6))), ?? 8.)

 :

PG
smantha
Lapis Lazuli | Level 10
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;

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 613 views
  • 1 like
  • 3 in conversation