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-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!

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