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-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
  • 2 replies
  • 419 views
  • 1 like
  • 3 in conversation