BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aidan
Quartz | Level 8

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 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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

 

View solution in original post

4 REPLIES 4
Patrick
Opal | Level 21

@Aidan

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.

Aidan
Quartz | Level 8

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.

 

ItemDate 1Days 1 
122-Apr-144 
211-Jun-143 
327-Feb-14114 

 

 

Patrick
Opal | Level 21

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

 

Aidan
Quartz | Level 8
This looks great Patrick I can work with this now, thanks very much for your quick response

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
  • 4 replies
  • 800 views
  • 2 likes
  • 2 in conversation