I am starting from scratch and want to create a dataset that has daily dates (e.g., starting 03/15/2020 through something that would be today's date whenever it is run) for each state (see below for example). I'll then use that as my base to fill in my other conditional variables. How can I do this?
Date State
03/15/2020 AK
03/15/2020 AL
............. ....
03/15/2020 WY
03/16/2020 AK
03/16/2020 AL
and so on through 04/23/2020 (or whatever the current date is for the day it is being run)
Thanks!
data want;
t=today();
do date='15MAR20'd to t by 1;
do state='AL','AK'; /* you type the rest, I'm lazy */
output;
end;
end;
format date yymmdd.;
drop t;
run;
data want;
t=today();
do date='15MAR20'd to t by 1;
do state='AL','AK'; /* you type the rest, I'm lazy */
output;
end;
end;
format date yymmdd.;
drop t;
run;
or if you've already got a table with the states:
proc sql;
create table have_states as
select distinct MapIdName as State
from sashelp.gcstate
where isoalpha3='USA'
;
quit;
data want;
set have_states;
format dt date9.;
do dt='15Mar2020'd to today();
output;
end;
run;
proc print data=want(obs=5);
run;
Do your states have to include the US protectorates like Puerto Rico or Virgin Islands?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.