I have a "start date" and I want to creates a series of daily dates from that date for each individual person in my code.
How do I do this?
Maybe by using a loop in a data step, if your date is a sas-date. Posting example data of what you have and showing what you expect as result will help us to help you.
please try the below code untested code , I am assuming that the start_date is numeric date
data want;
set have;
do i = start_date to today();
output;
end;
run;
If you have SAS/ETS license (check using PROC PRODUCT_STATUS) you can use the TIMESERIES procedure to fill the missing dates and impute the values if you're so inclined. You can set it to carry the last observation forward or assign it 0 or missing.
Here's an example where I fill in missing months (after I delete them in the first step for testing).
/*1*/
data ibm;
set sashelp.stocks;
where stock='IBM';
if month(date)=7 then
delete;
run;
proc sort data=ibm;
by date;
run;
/*2*/
proc timeseries data=ibm out=ibm_no_missing;
id date interval=month start='01Aug1986'd end='01Dec2005'd;
var open;
run;
Just change the start and end dates. Just noticed @Reeza's comment, edited to include a persons list, then merged the two files
/* Specify start and end dates*/
%let start_date=%str(1JAN2020);
%let end_date=%str(1APR2020);
data daily;
date_N="&start_date"d;
do while (date_N<="&end_date"d);
output;
date_N=intnx('day', date_N, 1, 's');
end;
format date_N date9.;
run;
data persons;
input name $;
cards;
John
Mary
Sally
Harry
;
proc sql;
create table comb as
select * from persons,daily
order by name;
quit;
I am definitely confused. Is there a way to do that with the intnx function? How would I do it with time series.
data web.finalgoal;
set web.goaldata;
randomization_date=start_date;
I dont have a variable for end_date do I need to create one?
by study_id;
I have broken this down into steps for you. Assuming randomization_date is numerical date values.
Untested code for your time series
proc sql;
select min(randomization_date),max(randomization_date)
into :startdate, :enddate
from web.goaldata;
quit;
data daily;
date_N="&start_date"d;
do while (date_N<="&end_date"d);
output;
date_N=intnx('day', date_N, 1, 's');
end;
format date_N date9.;
run;
proc sql;
create table studies as
select distinct study_id from web.goaldata;
quit;
proc sql;
create table web.finalgoal as
select * from studies,daily
order by studies;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.