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..??
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.
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.
I also edited your subject line. "SAS Datastep" is very uninformative with respect to your question.
Thankyou So Much.
It got it and the code worked.
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.
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.