BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5

data a;

input id$ 1-10;

b=index(id,'!');

c=countc(id,'!');

cards;

1!2!3445!!

run;

Hi i want the position of the Exclamation mark '!' i have tryed the index function but it will give the first occurence but i want the second ,third and fourth

occerance also how can i do by countc i founded the count of  Exclamation mark '!' but i want the postions for 2nd to 4th  Exclamation mark '!'..

3 REPLIES 3
art297
Opal | Level 21

You can always use findc and, after finding the first position, use that value+1 as the starting point for a subsequent search.

art297
Opal | Level 21

I think that the following does what you wanted:

data a (keep=id i position);

  informat id $30.;

  input id;

  delimiter='!';

  position=0;

  i=1;

  do while (substr(id,position+1) ne "");

    position=position+findc(substr(id,position+1),delimiter);

    output;

    i+1;

  end;

cards;

1!2!3445!!!

;

run;

proc print;

run;

which, for the above example, produces:

                         Obs        id         position    i

                             1     1!2!3445!!!        2       1

                             2     1!2!3445!!!        4       2

                             3     1!2!3445!!!        9       3

                             4     1!2!3445!!!       10       4

                             5     1!2!3445!!!       11       5

Ksharp
Super User

After check documentation.I found this:

data a;
input id$ 1-10; 
one=findc(id,'!',1);
two=findc(id,'!',one+1);
three=findc(id,'!',two+1);
four=findc(id,'!',three+1);
put one= two= three= four=;
cards;
1!2!3445!!
;
run;

Ksharp

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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