BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BETO
Fluorite | Level 6
I have a code that Id the day of week but its not working here is what i have

Data want;
Set have;
Retain weekno 0;
Length weektext $30;
If weekday (date)=1 then weekno+1;
If weekno>0 then weektext="week" !! Strip(put(weekno,2.))!! " " !! Strip(put(date,monname.));
My date is formatted yymmddd10.
When i run code the output is 0 for all entries im pulling month worth of data ...thanks for assistance
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
9 REPLIES 9
PeterClemmensen
Tourmaline | Level 20

This problem seems easier with the Week Function

BETO
Fluorite | Level 6
Thanks for the quick response the reason why i am using weekday is because i will be reporting on performance by 1st week of the month 2nd week of the month 3rd week and 4th
ballardw
Super User

"Not working" is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. 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.

 

 

 

BETO
Fluorite | Level 6
There are no errors in the log i tried this and it gave me what i needed
Data table;
Set table:
Week=intck('week',intnx('month',day,0) ,day) +1;
BETO
Fluorite | Level 6
Fyi cant post copy and paste code work restrictions
mkeintz
PROC Star

Perhaps you can make up synthetic data to  reproduce the problem, with a log you can publish.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
BETO
Fluorite | Level 6
Now that i id week 1 of the month is there a way to get it to sure it by date range for example
Date sales
09/03/19 - 09/06/19. $0000.00
09/09/19 - 09/13/19. $0000.00
09/16/19 - 09/20/19 $00000.00
09/23/19 - 09/27/19. $00000.00

The data looks like this
Date. Sales
09/09/19. 0000
09/10/19. 0000
09/13/19. 0000
09/15/19. 0000
09/16/19: 0000
09/24/19. 0000
09/27/19. 0000
ballardw
Super User

@BETO wrote:
Now that i id week 1 of the month is there a way to get it to sure it by date range for example
Date sales
09/03/19 - 09/06/19. $0000.00
09/09/19 - 09/13/19. $0000.00
09/16/19 - 09/20/19 $00000.00
09/23/19 - 09/27/19. $00000.00

The data looks like this
Date. Sales
09/09/19. 0000
09/10/19. 0000
09/13/19. 0000
09/15/19. 0000
09/16/19: 0000
09/24/19. 0000
09/27/19. 0000

 

Where does this interval come from?

09/03/19 - 09/06/19?

I think you may be excluding holidays now but have not explicitly stated that anywhere.

So what "interval" would expect for values in the first week of July 2019 where July 4 is a holiday that appears on Thursday??, or Christmas, New Years as other holidays that change day of the week? or Thanksgiving that is always a Thursday.

 

I think your "interval" display needs some additional description, rules and example in an out data. The example "have" data is easy. Here is a calendar worth:

data have;
  do date= '01Jan2019'd to '31Dec2019'd;
     output;
  end;
  format date date9.;
run;

Now provide examples of the interval value for each of those dates.

Reeza
Super User
How are your weeks of the month calculated? Ie is it first 7 days of the month = first week, day 8 to 14 is second week? If so, use day of MONTH and MOD() to get the week number pretty easily.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 989 views
  • 2 likes
  • 5 in conversation