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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
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;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
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;
--
Paige Miller
Patrick
Opal | Level 21

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;

 

ballardw
Super User

Do your states have to include the US protectorates like Puerto Rico or Virgin Islands?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 790 views
  • 4 likes
  • 4 in conversation