BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Gil_
Quartz | Level 8
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
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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. 

View solution in original post

15 REPLIES 15
novinosrin
Tourmaline | Level 20

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;

Reeza
Super User

Are periods your delimiter?

skyvalley81
Obsidian | Level 7

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;

Reeza
Super User

Because you’re looking for words, I’d probably recommend INDEXW or FINDW

skyvalley81
Obsidian | Level 7
HI Reeza, i totally agree these are two alternative options too.
ballardw
Super User

@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.

Gil_
Quartz | Level 8
Thanks for responding I put in your code
Data test4;
Set test4;
OUTPUT = ifc(INDEX(STRIP(Schedule),STRIP( today))>0, 'T', 'F');
RUN;


The output is F FOR all if the entries
Today date shows Thu. And schedule has and entry of THU AND OUT PUT IS FALSE SHOULD BE TRUE
Reeza
Super User

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.

skyvalley81
Obsidian | Level 7

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.

 

 

Gil_
Quartz | Level 8
Ok I realized that the Today is a number and schedule is character .. I have
Data test4;
Set test4;
Name=put (today,4.0)
Run;

To convert today to number I get the sas format of 21E3. I need it to be character to defect Fri
Gil_
Quartz | Level 8
To be Text FRI
novinosrin
Tourmaline | Level 20

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');

Gil_
Quartz | Level 8
To answer 1st question yes its a number its formatted Downame3. I inserted your code the error I get is

72-185 the INDEX function call has too many arguments.

Error 71-185 the IFC function call does not have enough arguments
novinosrin
Tourmaline | Level 20

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 15 replies
  • 2344 views
  • 1 like
  • 5 in conversation