How to add 21 days

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 78
Accepted Solution

How to add 21 days

Hi team,
I have a table that uses today dste and I need to add 21 days to it here is what data looks and what I need

Id freq dos lot total

That's what I have i would need a col for today's date and based on that date i would need 21 days added as labels
Today date id freq dos lot total 06/22/17 06/23/17 06/24/17 06/25/17.....

Accepted Solutions
Solution
‎06-28-2017 01:30 AM
PROC Star
Posts: 754

Re: How to add 21 days

[ Edited ]

I'm not entirely sure what you are asking, but if you want to add 21 days to todays date, then simply do

 

data _null_;
   todayplus21 = today() + 21;
   format todayplus21 date9.;
   put todayplus21;
run;

http://sasnrd.com/date-basics/

 

View solution in original post


All Replies
Super User
Posts: 11,343

Re: How to add 21 days

In Today date id freq dos lot total 06/22/17 06/23/17 06/24/17 06/25/17....

These cannot be variable names: 06/22/17 06/23/17 06/24/17 06/25/17

SAS variable names are _ or letter followed by _, letter or digit. NO / and cannot start with 0.

 

What values are you going to assign to those new variables? If you don't have a value why have the 21 additional variables?

 

This sounds like you may be trying to replicate some process that was originally done in a spreadsheet. If so you might be much better off describing your starting data and where this ends. Generally having data such as you propose with a separte column for each value of something (dates in this case) is MUCH better processed with a single variable to inicate that value group and another to hole the value.

There are many tools that work much better with data structured that way and then as a last step create a report with that group as a column heading.

Frequent Contributor
Posts: 78

How to add 21 days to data set

Hi team,
I have a table that uses today dste and I need to add 21 days to it here is what data looks and what I need

Id freq dos lot total

That's what I have i would need a col for today's date and based on that date i would need 21 days added as labels
Today date id freq dos lot total 06/22/17 06/23/17 06/24/17 06/25/17.....
Super User
Posts: 19,815

Re: How to add 21 days

It's not clear what you're asking here. 

 

Please do not post the same question multiple times. I've merged them into one question now. 

Solution
‎06-28-2017 01:30 AM
PROC Star
Posts: 754

Re: How to add 21 days

[ Edited ]

I'm not entirely sure what you are asking, but if you want to add 21 days to todays date, then simply do

 

data _null_;
   todayplus21 = today() + 21;
   format todayplus21 date9.;
   put todayplus21;
run;

http://sasnrd.com/date-basics/

 

Trusted Advisor
Posts: 1,570

Re: How to add 21 days

Before adding 21 days, you should describe your input:

what is the variable name that you want to add to it the 21 days? is it character or numeric type?

if numeric - is it a sas date? if not, what format is it (ddmmyyyy or yymmdd or date9. etc.)

 

The answer to your question will change according to your answers to those questions.

Frequent Contributor
Posts: 78

Re: How to add 21 days

Hi guys thanks so much for response what I need to do add 21 days as of today I didn't abt labels not being number so day of week would be good for example Today date id freq dos lot total thur Fri sat sun mon tues wed ....whst i want to add once that part been Id is the total amt base on freq for example

Today date id. freq. total. thur Fri. sat. sun
06/21/17. A1 Fri sun. 150. 0. 150. 0. 150
Respected Advisor
Posts: 4,173

Re: How to add 21 days

@Gil_

To get good answers you need to provide sufficient information in your question.

A very good way to provide such information is for you to post a SAS data step creating sample data and then you show us how your desired result should look like.

 

@draycut already posted sample code. Have you looked into it and understood what it does? May be that's already the solution for you. 

Frequent Contributor
Posts: 78

Re: How to add 21 days

Sorry I didn't post my question 2x i rec error message 1st time so I hit post again that's why you see same question
Frequent Contributor
Posts: 78

Re: How to add 21 days

Thanks for code it only give one day I would need 21 days in day week (Mon Tue wed thur Fri sat sun) I will provide dataset
Super User
Posts: 19,815

Re: How to add 21 days

You need to create an array and then assign values.

 

array days(21) days1-days21;

do i=1 to 21;
days(i) = i + date;
end;

 

 

 

 

Frequent Contributor
Posts: 78

Re: How to add 21 days

Hi Reeza I try your example it didn't work should it be like a data set ?
Respected Advisor
Posts: 4,173

Re: How to add 21 days

@Gil_

Statements like "it didn't work" without detailed explanation what you've done and what didn't work are not helpful.

 

1. Provide a fully working data step creating sample data

2. Explain what you want to do

3. Provide the desired output to illustrate what you've explained in words how the outcome should look like (as a SAS data step as well or just a table which lists the results you would like to get)

 

Once we understand what you have and what you need we can help you; else things will just go in circles waisting everbodys time.

Frequent Contributor
Posts: 78

Re: How to add 21 days

I realized I provided col not needed for my request.. I apologize Fri was a bad day ... Thank you for assistance here is how data looks and output needing
Dos. total. Mon. Tue. Wed thur. Fri Sat
Tue Fri. 125. 125. 125

WED. 25. 25

THANK YOU AGAIN FOR ASSISTANCE
Frequent Contributor
Posts: 78

Re: How to add 21 days

I will admit i have never used arrays I Google for examples 1st before asking for assistance for some reason it flew over my head I use the array provide above
Data table;
Set table;
array days(21) days1-days21; do i=1 to 21; days(i) = i + date; end;

The error i get is alphabetic prefixes for enumerated variable (days1-days21) are different. Too few variable define for the dimensions specified for the array day.
Undeclared array reference :days.
Syntax error, expecting one of the following : [ (
Syntax error statement will be ingored
☑ This topic is solved.

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

Discussion stats
  • 18 replies
  • 383 views
  • 0 likes
  • 6 in conversation