Could you please explain me what this little piece of code is doing?
I have difficulty understanding what the >0 is doing and also the -1???
data abc;
set xyz(drop=fmtname rename=(start=drg label=desc));
if index(desc,"W MCC")>0then GrpDsc=substr(desc,1,(index(desc,"W MCC")-1));
elseif index(desc,"W/O MCC")>0then GrpDsc=substr(desc,1,(index(desc,"W/O MCC")-1));
elseif index(desc,"W CC")>0then GrpDsc=substr(desc,1,(index(desc,"W CC")-1));
elseif index(desc,"W/O CC/MCC")>0then GrpDsc=substr(desc,1,(index(desc,"W/O CC/MCC")-1));
else
GrpDsc=desc;
run;
Regards
Karun, You can answer such questions by simply reading the documentation. The index function: "Searches a character expression for a string of characters, and returns the position of the string's first character for the first occurrence of the string."
Thus, if it returns a number greater than 0 it found the string starting at the returned location.
Since substr, in turn, extracts characters starting from (in our case position 1), and extracts X characters (in your case the second value), it is extracting up to but not including the found string.
Karun, You can answer such questions by simply reading the documentation. The index function: "Searches a character expression for a string of characters, and returns the position of the string's first character for the first occurrence of the string."
Thus, if it returns a number greater than 0 it found the string starting at the returned location.
Since substr, in turn, extracts characters starting from (in our case position 1), and extracts X characters (in your case the second value), it is extracting up to but not including the found string.
Hi
Thanks for the detailed explanation. I scanned through the documentation and may be I didnt check the right page. I will make it a habit.
Thanks
Karun,
Just like Arthur suggested, it would be best for you to research on the below link looking for SAS Functions and call routines. Ideally, a discussion on application orientated medium to complex queries is rather interestingly appreciated than merely asking answers on learning resources. Merry Christmas.
Cheers from England,
Andy
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212242.htm
Hi,
I appreciate your valuable sugestions in this regard.
Thanks
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.