BookmarkSubscribeRSS Feed
sam369
Obsidian | Level 7

 

Hi All,

 

 I want to create variable with all the dates between the dates ranges.

 

for example

 

have:

id      orddt     recdt

100   1/5/15   2/3/15

100    1/17/15   3/6/15

......

....

101 ...............

101 ......

want;

 

1d  orddt1         recdt1       dt1                            dt2                                               orddt2                       recdt2

100 1/5/15      2/3/15    1/5/15(first orddt)

100 1/5/15      2/3/15    1/6/15

100 1/5/15      2/3/15   1/7/15

100 1/5/15      2/3/15   1/8/15

...................

......................

100 1/5/15      2/3/15  1/17/15                              1/17/15( 2nd orddt)                  1/17/15   3/6/15

100 1/5/15      2/3/15  1/18/15(upto first recdt)     1/18/15                                      1/17/15   3/6/15

........................

....................

100 1/5/15      2/3/15   2/2/15

100 1/5/15      2/3/15   2/3/15

100                                                                        2/4/15                                     1/17/15   3/6/15

100                                                                        2/5/15                                      1/17/15   3/6/15

............................

..............................

..............................

100                                                                       3/6/15(2nd recdt)                    1/17/15   3/6/15

 

my code:

 

data want;

  set have;

 by id;

array d[&max] dt1-dt&max.;

  do i=1 to &max;

     do dt=orddt    to     recdt;

       d[i]=dt;

       output;

    end;

end;

format dt-dt&max. date9.;

run;

 

i am missing some thing in my code.

 

Thanks

Sam

5 REPLIES 5
Reeza
Super User
Whats the logic behind date2 variable?
sam369
Obsidian | Level 7

Same , orddt to recdt

 

Thanks

Sam

Reeza
Super User
That format doesn't make sense to me, in terms of future usage.

The number of overlaps/max could get unwieldy quickly.

Consider using a multistep process

1. Loop from ord to rec date and ouput one record per day per order.
2. Sort by ID, Date
3. Transpose via proc transpose. You may need to add an order var - not sure about this step.
sam369
Obsidian | Level 7

Thanks Reeza!!! . I tried the way you suggested, but doesnt work!!! i created a order variable!! still not able to get what i want

Any suggestion will be helpful

 

Thanks

Sam

Reeza
Super User

Post your code and define doesn't work.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 1276 views
  • 0 likes
  • 2 in conversation