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-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!

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
  • 3 replies
  • 568 views
  • 4 likes
  • 4 in conversation