🔒 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 03-16-2022 02:51 AM
(4390 views)
I am not understanding below program how it resolved
Data a;
Input string 7.;
Reverse=reverse (string);
pos=indexc(reverse,"., ");
Last_word=substr (string,7-pos+2);
Cards;
ABC.DEF
JHG GHTY
HYT,XYZ
;
RUN;
HERE LAST_WORD STATEMENT HOW IT WILL RESOLVE, PLEASE EXPLAIN
Data a;
Input string 7.;
Reverse=reverse (string);
pos=indexc(reverse,"., ");
Last_word=substr (string,7-pos+2);
Cards;
ABC.DEF
JHG GHTY
HYT,XYZ
;
RUN;
HERE LAST_WORD STATEMENT HOW IT WILL RESOLVE, PLEASE EXPLAIN
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The doc is your friend. Here is a link to the SUBSTR doc.
- pos = the location of a delimiter in the reverse string. The delimiters are '.' or ',' or ' '.
- Each string in your data is 7 characters long, so 7-pos gives the position of the character BEFORE the delimiter.
- Therefore 7-pos+2 gives the position of the character AFTER the delimiter.
- The SUBSTR function copies all characters from that position until the end of the string.
12 REPLIES 12
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Insert a put _all_; statement
Run the program.
Examine log.
Data never sleeps
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your response,
I want to know how this is working,means flow
Last _word=Substr(string,7-pos+2);
I want to know how this is working,means flow
Last _word=Substr(string,7-pos+2);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The doc is your friend. Here is a link to the SUBSTR doc.
- pos = the location of a delimiter in the reverse string. The delimiters are '.' or ',' or ' '.
- Each string in your data is 7 characters long, so 7-pos gives the position of the character BEFORE the delimiter.
- Therefore 7-pos+2 gives the position of the character AFTER the delimiter.
- The SUBSTR function copies all characters from that position until the end of the string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think you want to declare String to be a CHARACTER variable. Currently, it is a numeric variable. To declare a character variable, put a '$' symbol after the name of the variable on the INPUT statement, like this:
Input string $ 7.;
After making that change, rerun the program and examine the output. Let us know if you still have questions!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
flow of work
Last _word=Substr(string,7-pos+2);
*7-pos+2(here pos value:4)*
Last _word=Substr(string,7-pos+2);
*7-pos+2(here pos value:4)*
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What determines `pos`? Please provide some example data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Actually this is total dataset, I want to know how(Last_word=substr (string,7-pos+2);).
Data a;
Input string 7.;
Reverse=reverse (string);
pos=indexc(reverse,"., ");
Last_word=substr (string,7-pos+2);
Cards;
ABC.DEF
JHG GHTY
HYT,XYZ
;
RUN;
Data a;
Input string 7.;
Reverse=reverse (string);
pos=indexc(reverse,"., ");
Last_word=substr (string,7-pos+2);
Cards;
ABC.DEF
JHG GHTY
HYT,XYZ
;
RUN;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@PurushReddy wrote:
flow of work
Last _word=Substr(string,7-pos+2);
*7-pos+2(here pos value:4)*
What is your question?
--
Paige Miller
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Substr(string,7-pos+2),
How this is working, I am not getting, what is the flow of.
How this is working, I am not getting, what is the flow of.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your task can be much easier solved by using the right tool (Maxim 14), which is the SCAN function:
data a;
input string $7.;
last_word = scan(string,-1,"., ");
cards;
ABC.DEF
JHG GHTY
HYT,XYZ
;