BookmarkSubscribeRSS Feed
Saikiran_Mamidi
Obsidian | Level 7

Interview Question to my friend.

 

x=A,B,C,D,E,F,G ;

He wants  to find 4th  comma or 5th comma.

 

I have given this answer.

data a;
x='A,B,C,D,E,F';
run;
%let p=9;
data find_comma;
set a;
fouth_comma=find(x,',',&p);
run;

Is it correct? or wrong?

Interview asked me to write dynamically. 

Please correct if I'm  wrong.

They want dynamically?

3 REPLIES 3
Ksharp
Super User
data _null_;
x='A,B,C,D,E,F';

n=4;
call scan(x,n,p,l,',');
position=p+l ;
putlog 'n=' n 'position=' position;


n=5;
call scan(x,n,p,l,',');
position=p+l ;
putlog 'n=' n 'position=' position;

run;
gamotte
Rhodochrosite | Level 12

Hello,

 

data _null_;
    x='A,B,C,D,E,F';

    do n=4, 5;
        position=length(prxchange(cats('s/^(([^,]*,){',n,'}).*$/$1/'),1,x));
        put n= position=;
    end;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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