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 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.....
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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

18 REPLIES 18
Gil_
Quartz | Level 8
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.....
ballardw
Super User

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.

Reeza
Super User

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. 

PeterClemmensen
Tourmaline | Level 20

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/

 

Shmuel
Garnet | Level 18

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.

Gil_
Quartz | Level 8
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
Patrick
Opal | Level 21

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

 

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

Gil_
Quartz | Level 8
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
Gil_
Quartz | Level 8
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
Reeza
Super User

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;

 

 

 

 

Gil_
Quartz | Level 8
Hi Reeza I try your example it didn't work should it be like a data set ?
Patrick
Opal | Level 21

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

Gil_
Quartz | Level 8
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
Gil_
Quartz | Level 8
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 18 replies
  • 1438 views
  • 0 likes
  • 6 in conversation