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

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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.

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

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.

robertrao
Quartz | Level 8

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

Andygray
Quartz | Level 8

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

robertrao
Quartz | Level 8

Hi,

I appreciate your valuable sugestions in this regard.

Thanks

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 1025 views
  • 0 likes
  • 3 in conversation