BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Beto16
Obsidian | Level 7
Hi I have a macro
Data _null_;start _ date = today ();;
Call symput ('dt' , " ' "||put(start_date-1 ,yymmdd10.)||" ' ");

Call symput ('dt', " ' "||put (end _ date -1,yymmdd10.)||" ' ");

It doesn't bring any info because the data that I'm pulling from is a datetime 25.6


How do I convert my macro to pick up the datetime25.6 format?
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

1) Start_date is a date value. If you want a DATETIME value you need to make one. Easiest is

DateTimeValue = DHMS(today(),0,0,0);  to make one with zero for hour, minute and second.

If you want it for the day before

DateTimeValue = DHMS(today() -1,0,0,0);  (or use INTNX function)

To get a macro variable with a DATETime appearance then you need to specify a DATETIME format with PUT. Since you know that you want datetime25.6

Call symput('dt',put(Datetimevalue,datetime15.6));

 

Some other things, If you use Call Symput('dt', ..) twice as shown only the last value will be kept. You need separate macrovariable names, perhaps dtstart and dtend.

 

Thing very carefully about using quotes in the actual definition of a macro variable. Also HOW exactly will you use the resulting macrovariables? If for titles or text you would not want the quotes. If for comparisons with other datetime valued variables you don't need to use a datetime format as the numeric value would work.

 

Your comment: It doesn't bring any info because the data that I'm pulling from is a datetime 25.6

doesn't have any meaning in the context presented. You are assuming we know a lot more than has been shown.

View solution in original post

8 REPLIES 8
Beto16
Obsidian | Level 7
Fyi here is example of data 09may2016:12:33:09.000000
DartRodrigo
Lapis Lazuli | Level 10

Hi mate.

 

%let tdate = %sysfunc(today(),datetime25.6);
%put &tdate.;

Is this what you need ?

 

Hope this helps

ballardw
Super User

1) Start_date is a date value. If you want a DATETIME value you need to make one. Easiest is

DateTimeValue = DHMS(today(),0,0,0);  to make one with zero for hour, minute and second.

If you want it for the day before

DateTimeValue = DHMS(today() -1,0,0,0);  (or use INTNX function)

To get a macro variable with a DATETime appearance then you need to specify a DATETIME format with PUT. Since you know that you want datetime25.6

Call symput('dt',put(Datetimevalue,datetime15.6));

 

Some other things, If you use Call Symput('dt', ..) twice as shown only the last value will be kept. You need separate macrovariable names, perhaps dtstart and dtend.

 

Thing very carefully about using quotes in the actual definition of a macro variable. Also HOW exactly will you use the resulting macrovariables? If for titles or text you would not want the quotes. If for comparisons with other datetime valued variables you don't need to use a datetime format as the numeric value would work.

 

Your comment: It doesn't bring any info because the data that I'm pulling from is a datetime 25.6

doesn't have any meaning in the context presented. You are assuming we know a lot more than has been shown.

Beto16
Obsidian | Level 7
Your right sorry about that I tried your code ...the macro example it should be dt and dt1 I used as a between state. ...I'm getting an warning apparent invocation of macro the not resolved

Data _null_;start _ day =today ();
Call symput ('dt', " ' "|| put (start_date-1,datetime15.6));


Prod date = &dt. When code runs it outputs 01jan60:06:43

this is what data on table looks like

09may2016:12:33:09.000000
ballardw
Super User

Please show the code actually used to generate the macro value AND the code where you attempt to use the variable and the log.

 

And did you pay attention to the use of DHMS to create an actual DATETIME type variable in the code I posted previously? 

 

Your example code using TODAY() generates a DATE, not a DATETIME. Since SAS stores dates as number of days since 1 Jan 1960 and DATETIME as number of SECONDS there are significant differences of the results when you treat a date, as in your example, as if it were a datetime.

 

 

Beto16
Obsidian | Level 7
I'm now using
Data _null_;
Start_date= today ();
Call symput ('dt' , " ' "||put (dhms (start_date-1,0,0,0),datetime.)||" 'dt"

Call symput ('dt1' , " ' "||put (dhms (start_date-1,0,0,0),datetime.)||" 'dt");
run;

where open _date between dt. And dt1.


Here is error message
Teradata odbc teradata driver Tera data database syntax error ,expected something like an UDFCALLNAME keyword '.' And the 'AND' the keyword .

Astounding
PROC Star

There's a standard remedy for this type of problem.  Get the program to work without using any macro language.  Once you figure out what Teradata is looking for, it won't be hard to turn that into a macro.  But you have to have a working program first.

ballardw
Super User

You still are not showing the code USING the macro variables. The error message looks incomplete. If the Error is in the log then copy the code and error from the log post it.

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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