## How to find date of week

Solved
Frequent Contributor
Posts: 114

# How to find date of week

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

Accepted Solutions
Solution
‎12-18-2017 02:36 PM
PROC Star
Posts: 1,817

## Re: How to find date of week

[ Edited ]

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.

All Replies
PROC Star
Posts: 1,817

## Re: How to find date of week

[ Edited ]

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;

Super User
Posts: 23,754

## Re: How to find date of week

Are periods your delimiter?

Occasional Contributor
Posts: 15

## Re: How to find date of week

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;

Super User
Posts: 23,754

## Re: How to find date of week

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

Occasional Contributor
Posts: 15

## Re: How to find date of week

HI Reeza, i totally agree these are two alternative options too.
Super User
Posts: 13,563

## Re: How to find date of week

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.

Frequent Contributor
Posts: 114

## Re: How to find date of week

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
Super User
Posts: 23,754

## Re: How to find date of week

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.

Occasional Contributor
Posts: 15

## Re: How to find date of week

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.

Frequent Contributor
Posts: 114

## Re: How to find date of week

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
Frequent Contributor
Posts: 114

To be Text FRI
PROC Star
Posts: 1,817

## Re: How to find date of week

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

Frequent Contributor
Posts: 114

## Re: How to find date of week

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
Solution
‎12-18-2017 02:36 PM
PROC Star
Posts: 1,817

## Re: How to find date of week

[ Edited ]

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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