works for me :
data have;
input id:$2. Schedule:$20.;
cards;
A1 MON-TUE WED
A2 WED-SAT WED
A3 MON-TUE-FRI WED
;
data want;
set have;
today=today();
OUTPUT = ifc(INDEX(STRIP(Schedule),STRIP( upcase(put(today, Downame3.))))>0, 'T', 'F');
run;
You may have to show your data to help me understand better.
data have;
input id $ Schedule & $12. Today $;
datalines;
A1. MON TUE WED False
A2. WED SAT WED True
A3. MON TUE WED WED TRUE
;
data want;
set have;
if index(STRIP(Schedule),STRIP( today))>0 then output='T';
ELSE OUTPUT='F';
RUN;
OR
data want;
set have;
OUTPUT = ifc(INDEX(STRIP(Schedule),STRIP( today))>0, 'T', 'F');
RUN;
Are periods your delimiter?
Hi Gil_
Check if this is what you want.
data have;
input id:$2. Schedule:$20. Today:$20.;
cards;
A1 MON-TUE WED
A2 WED-SAT WED
A3 MON-TUE-WED WED
;
run;
data want;
set have;
outputs = ifc(index(strip(upcase(Schedule)), strip(upcase(today)))>0, "TRUE", "FALSE");
run;
Because you’re looking for words, I’d probably recommend INDEXW or FINDW
@Gil_ wrote:
Hi I have a data set looks like this
Id. Schedule. Today. Output
A1. MON TUE. WED. False
A2. WED SAT. WED. True
A3. MON TUE WED. WED. TRUE
I need to look in col Today see if it matches in the schedule for True or False
Provide what the output is supposed to look like for that example.
And tell us where your variables start and end. It isn't easy to tell from that example. Be aware, the message windows of this forum reformat text by removing blank characters and possibly other things. If your text as shown above doesn't match what you intended to post, try again by pasting into a code box opened using the forum {I} menu icon. That text box will not reformat text.
Better is to provide data step code to recreate your data. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
Does the full demo code above work?
If so, there's something different about your dataset that we don't know and can't see.
It would be good if you provide it us your data in data step format in order to understand what is going wrong.
The reasons that you get incorrect results might be different character cases in the schedule and today variables.
If this is the case you can use the UPCASE function in order to ensure that the variables have the same character cases or the i modifier in the FIND functions. Check the codes below:
output = ifc(index(strip(upcase(schedule)),strip(upcase(today)))>0, 'T', 'F');
output = ifc(find(strip(schedule),strip(today), "i")>0, 'T', 'F');
Also make sure that the variables have the same levels. For example if the schedule variable is MON and the today Monday this code wont work.
Hope it helps.
do you mean your today is a variable that is a numeric sasdate value, if yes-
This may help-
OUTPUT = ifc(INDEX(STRIP(Schedule),STRIP( upcase(put(today, weekdate3.))))>0, 'T', 'F');
works for me :
data have;
input id:$2. Schedule:$20.;
cards;
A1 MON-TUE WED
A2 WED-SAT WED
A3 MON-TUE-FRI WED
;
data want;
set have;
today=today();
OUTPUT = ifc(INDEX(STRIP(Schedule),STRIP( upcase(put(today, Downame3.))))>0, 'T', 'F');
run;
You may have to show your data to help me understand better.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.