Hi there
Don't know if this is feasible in SAS but I know its possible in other tools.
If I have a data set and there is 2 dates e.g.
1/Jan/2017 and 22/Apr/2017 so there is 111 days betwen these 2 dates.
What I want to achieve is distributing these days to a particular month, so the first 30 days go to Jan 17, the second 28 go to Feb 17, 31 to Mar and 22 to Apr
Any ideas if this can be done?
Kind Regards
Aidan
You haven't shown us how the desired result should look like so not sure if below will give you what you're after. It should point you into the right direction though especially when it comes to working with SAS Date values.
data have;
infile datalines truncover dlm=' ';
input Item Date:anydtdte. Days;
format date date9.;
datalines;
1 22-Apr-14 4
2 11-Jun-14 3
3 27-Feb-14 114
;
run;
data want;
set have;
format target_date date9.;
do target_date=date to date+days;
output;
end;
run;
There is certainly a solution but you need to better explain what you have and what you need; i.e: where are these 2 dates? On a single row in 2 variables and you want to generate multiple rows with consecutive dates?
Best provide a SAS data step which creates a HAVE data set and then show us how the desired result should look like.
So the below is something that I would have for instance.
So item 1 keeps the days to April 2014
Item 2 has 3 for Jun 2014
Item 3 then is spread across more than 1 month
Hope this helps.
Item | Date 1 | Days 1 | |
1 | 22-Apr-14 | 4 | |
2 | 11-Jun-14 | 3 | |
3 | 27-Feb-14 | 114 |
You haven't shown us how the desired result should look like so not sure if below will give you what you're after. It should point you into the right direction though especially when it comes to working with SAS Date values.
data have;
infile datalines truncover dlm=' ';
input Item Date:anydtdte. Days;
format date date9.;
datalines;
1 22-Apr-14 4
2 11-Jun-14 3
3 27-Feb-14 114
;
run;
data want;
set have;
format target_date date9.;
do target_date=date to date+days;
output;
end;
run;
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.
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.