data One;
input Date_Info $ 20.;
cards;
24Nov is Sunday
25Nov is Monday
26Nov is Tuesday
27Nov is Wednesday
28NOV IS THURSDAY
29nov is Friday
30NOV is SATURDAY
;
run;
data two;
set one;
a=scan(date_info,-1);
put a;
d=trim(a);
c=findw(date_info,d);
put c;
run;
Iam writing this code it giving c as zero always why?
In SAS data sets, variables have a fixed length. That length does not change from one observation to the next. Therefore ...
When you assign a value to A, SAS defines A as character, with a length of 20. It is possible that 20 characters would be needed to store A, so that's the length assigned.
Similarly, when you define D, SAS defines it as character with a length of 20. Again, it is possible that 20 characters would be needed to store its value, so that's the length assigned.
When the TRIM function executes, it does remove trailing blanks. However, the result gets stored in a variable that is defined as 20 characters long, so any blanks that were removed by TRIM get added back on again. As a result, FINDW cannot find that 20-character string with all those trailing blanks.
To remedy the situation, try:
c = findw(date_info, trim(a));
In SAS data sets, variables have a fixed length. That length does not change from one observation to the next. Therefore ...
When you assign a value to A, SAS defines A as character, with a length of 20. It is possible that 20 characters would be needed to store A, so that's the length assigned.
Similarly, when you define D, SAS defines it as character with a length of 20. Again, it is possible that 20 characters would be needed to store its value, so that's the length assigned.
When the TRIM function executes, it does remove trailing blanks. However, the result gets stored in a variable that is defined as 20 characters long, so any blanks that were removed by TRIM get added back on again. As a result, FINDW cannot find that 20-character string with all those trailing blanks.
To remedy the situation, try:
c = findw(date_info, trim(a));
thanks alot for explaining the logic. now im able to uderstand the flow how its going. once again thank you.
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!
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.