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

Data Test3 ;
Set Test2 ;
Format o_String $2000. ;
if _N_ = 1 then do;
O_String = "" ;
end ;
O_String = catx(" , ", O_String, " ") ;
find = Find(O_String,O_Level) ;
O_String = catx(" , ", O_String, O_Level) ;
new = Find(O_String,O_Level) ;
Retain O_String ;
Run ;

 

I am confused as why the column named find is always showing zero when the column named new is showing the correct value.

As per my understanding only the first row in find should show  a blank value otherwise it should also give some value but it is always giving a straight zero.

 

Can anyone help me with this..??

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

When assigning find, you are testing for the presence of o_level before you append it to o_string, so find will be zero unless the same value for o_level was already on the dataset.

But you also made the mistake of assuming that a shorter string will consist of less characters for SAS, which it doesn't. The find() function will take the padding of o_level with blanks into account, and only find a position if the visible value of o_level can be found padded with blanks in o_string:

data test2;
input o_level $;
cards;
xxx
yyy
zzz
xxx
;
run;

data test3;
set test2;
format o_string $2000.;
retain o_string "";
o_string = catx(" , ",o_string," ");
find = find(o_string,trim(o_level));
o_string = catx(" , ",o_string,o_level);
new = find(o_string,o_level);
run;

So I used the trim() function in the first test.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

When assigning find, you are testing for the presence of o_level before you append it to o_string, so find will be zero unless the same value for o_level was already on the dataset.

But you also made the mistake of assuming that a shorter string will consist of less characters for SAS, which it doesn't. The find() function will take the padding of o_level with blanks into account, and only find a position if the visible value of o_level can be found padded with blanks in o_string:

data test2;
input o_level $;
cards;
xxx
yyy
zzz
xxx
;
run;

data test3;
set test2;
format o_string $2000.;
retain o_string "";
o_string = catx(" , ",o_string," ");
find = find(o_string,trim(o_level));
o_string = catx(" , ",o_string,o_level);
new = find(o_string,o_level);
run;

So I used the trim() function in the first test.

DipeshGupta
Calcite | Level 5

Thankyou So Much.

It got it and the code worked.Smiley Happy

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1157 views
  • 1 like
  • 2 in conversation