BookmarkSubscribeRSS Feed
Tom
Super User Tom
Super User

It is probably a lot easy to play with getting the date and datetime value in a data step.  You can then use CALL SYMPUTX() to generate your macro variables.

data _null_;
  end=today();
  start=end-45 ;
  end_dt=dhms(end,0,0,0);
  start_dt=dhms(start,0,0,0);
  put (start end) (= yymmdd10.) (start_dt end_dt) (= datetime19.);
  call symputx('startdate',quote(put(start,yymmdd10.),"'"));
  call symputx('enddate',quote(put(end,yymmdd10.),"'"));
  call symputx('start_dt',quote(cats(put(start_dt,datetime19.)))||'dt');
  call symputx('end_dt',quote(cats(put(end_dt,datetime19.)))||'dt');
run;

Results:

start=2018-10-03 end=2018-11-17 start_dt=03OCT2018:00:00:00 end_dt=17NOV2018:00:00:00

555  %put &=startdate;
STARTDATE='2018-10-03'
556  %put &=enddate;
ENDDATE='2018-11-17'
557  %put &=start_dt;
START_DT="03OCT2018:00:00:00"dt
558  %put &=end_dt;
END_DT="17NOV2018:00:00:00"dt

Note that if you are going to use those date or datetime values in SAS code then there is no need to format them in human friendly ways.  You can just use the underlying integer values.

  call symputx('startdate_easy',start);
  call symputx('enddate_easy',end);
  call symputx('start_dt_easy',start_dt);
  call symputx('end_dt_easy',end_dt);
560  %put &=startdate_easy;
STARTDATE_EASY=21460
561  %put &=enddate_easy;
ENDDATE_EASY=21505
562  %put &=start_dt_easy ;
START_DT_EASY=1854144000
563  %put &=end_dt_easy ;
END_DT_EASY=1858032000

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 15 replies
  • 2140 views
  • 8 likes
  • 4 in conversation