BookmarkSubscribeRSS Feed
femiajumobi1
Quartz | Level 8
Data x;
array datex{*};
day=intnx('dtday', datex'dt, 3); /* +3 days */
run;

I have data x with variable datex in format mmddyy10. I need to create 3 more dates consecutively for each observation. for example please see below (index date for obs 1 = 01/01/2022 and  for obs 2 = 02/03/2022),

obs  datex                      

1      01/01/2022

1      01/02/2022

1      01/03/2022

1      01/04/2022 

2      02/03/2022 

2      02/04/2022    

2     02/05/2022    

2      02/06/2022  

 

How do I do this with array and INTNX? This and any other approach is well appreciated. Thanks in advance.

9 REPLIES 9
Kurt_Bremser
Super User

Your data step does not read anything, so it will have nothing to initialize the values.

You use the DTDAY interval, which is for datetimes, but you seem to want to work with dates.

So please show us the real data you have, with their real types (date or datetime), from which you want to get the dataset you show in your post.

femiajumobi1
Quartz | Level 8

Thanks, Kurt_Bremser, for your prompt response. That was a mistake. It is date not datetime. Please see below "Data A" and I will like to add 3 more dates incrementally by 1 to each of the observation to give me "Data B"
Data A
obs datex
1 01/01/2022
2 02/03/2022
.. ...................
n 10/24/2022

 

Data B
obs datex
1 01/01/2022
1 01/02/2022
1 01/03/2022
1 01/04/2022
2 02/03/2022
2 02/04/2022
2 02/05/2022

2 02/06/2022

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

n 10/24/2022

n 10/25/2022

n 10/26/2022

n 10/27/2022

Tom
Super User Tom
Super User

Is this what you are trying to do?

data have;
  obs+1 ;
  input datex :mmddyy. ;
  format datex yymmdd10.;
cards;
01/01/2022
02/03/2022 
;

data want;
  set have;
  do datex=datex to datex+3;
    output;
  end;
run;

proc print;
run;

Tom_0-1666639033866.png

Note: There is no need to use INTNX() when incrementing by the unit that the value is using.  Days for Dates,  Seconds for Time or DateTime.

femiajumobi1
Quartz | Level 8

Thanks, Tom, Yes this is is exactly what I am trying to do but in the context of a huge dataset.

Reeza
Super User

Size of data set is irrelevant, approach is the same.

 

data want;
  set have; *specify input data set;
  do datex=datex to datex+3; *increment date once for each day;
    output; *write record to data set;
  end;
run;
ballardw
Super User

@femiajumobi1 wrote:

Thanks, Tom, Yes this is is exactly what I am trying to do but in the context of a huge dataset.


So what should happen with other variables in the data set? Do you want three additional values of each variable? For the other variables to be missing on one or more of the added dates? Something else?

Tom
Super User Tom
Super User

@femiajumobi1 wrote:

Thanks, Tom, Yes this is is exactly what I am trying to do but in the context of a huge dataset.


You probably need to explain the larger context that made you think it made sense to quadruple the size of the dataset then.

What is the problem are trying to fix or the analysis you are trying to do?

What is the reason you thought it would help to replicate the data four times?

femiajumobi1
Quartz | Level 8

 

Tom, so, this is it:

the dataset is service data but I have to merge it with pharmacy data for a specific medication.  In my situation, when one gets a prescription at the hospital (service data), it is expected it would be filled within 3days at the pharmacy (pharmacy data), that's someone is expected to buy his medication within 3 days of being given a prescription at the hospital. 

 

Thus, I thought of creating a scenario of additional 3days (3 succeeding dates [date_x]) during which someone can fill his prescription at the pharmacy. I am interested in merging service data to a prescription that was filled within 3days in pharmacy data (pharmacy data has its own dates, date_y). And that what why I was thinking I need to create a window period of 3days for which I could merge the data such that the service aligns with the prescription received within 3days (not outside of the 3days), but I am not sure how to do this with INTNX and array at the merging phase.  

 

 

Reeza
Super User
No...you join within a three days interval. If you provide samples of each input data set and expected output someone can help you with the code.

I also question your three day interval, except in the case of opioids if you're doing opioid drug monitoring.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 518 views
  • 2 likes
  • 5 in conversation