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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1812 views
  • 1 like
  • 2 in conversation