Hello everyone! I will be very grateful if you help solve the problem.
I have two macro variables.
They look like this:
I want to create two new macro variables that should look exactly like this:
'29JAN16:11:07:33'dt and '29JAN16:14:21:01'dt
Is it possible? and if yes, please give the code
A slight modification to your code with %unquote to will work for the macro processor to function properly
where t1.t_start<=%unquote(&data_s);
albeit the bigger picture or purpose seems a little misleading
HI @olgazabelinasas Not sure if I am missing some puzzle here. Isn't this supposed to be as simple as
%let date_start=29JAN16:11:07:33;
%let date_start_new=%bquote('&date_start'dt);
%put &=date_start_new;
The same for the date_end. I am lazy to type
what does not work?
Here is the log:
822 %let date_start=29JAN16:11:07:33;
823
824 %let date_start_new=%bquote('&date_start'dt);
825
826 %put &=date_start_new;
DATE_START_NEW='29JAN16:11:07:33'dt
I want to create two new macro variables that should look exactly like this:
'29JAN16:11:07:33'dt and '29JAN16:14:21:01'dt
Macro variables, in general, should not be formatted. They should be numbers, not human readable text strings like above.
sorry, it is not work
Well, it should work. Show us what you did, and show us the LOG from SAS (the entire log for this part of your code, including the code, the WARNINGs, and the ERRORs), and explain what did work.
We need to see the ENTIRE log of this sequence where you create a macro variable and then try to use it. We do not want you to chop parts out and only show us selected parts.
While I can't tell what the error is until I see the entire log, again I repeat that your macro variables should not be formatted. In this case, and any other cases where you compare a SAS date/time or date variable to a macro variable, formatting the macro variable does not help, and often causes the program to fail.
For future reference, we don't like to see code or log as screen captures.
When you signed up for the SAS communities, you should have received an e-mail stressing the importance of providing code in a "code box" which is the running man icon, and providing the log in a "code box" which is the </> icon. Please follow these guidelines.
A slight modification to your code with %unquote to will work for the macro processor to function properly
where t1.t_start<=%unquote(&data_s);
albeit the bigger picture or purpose seems a little misleading
See Maxim 28. The raw, unformatted values work best.
I have a couple of questions.
First it is not clear how you generated those photographs from MACRO variables. You don't normally browse macro variables in a tabular presentation like that. Can you just use %PUT to write the values to the log and copy the text from the log (don't take a picture of the text).
Do you really want single quotes? It would be easier to generate using double quotes since single quotes suppress macro triggers.
%put "&date_start"dt "&date_end"dt ;
@Tom wrote:
I have a couple of questions.
First it is not clear how you generated those photographs from MACRO variables. You don't normally browse macro variables in a tabular presentation like that.
Maybe some use of the SASHELP.VMACRO view or the corresponding Dictionary table? Though I agree that looks somewhat suspicious.
Are those dates from 2016 or 1916? Do not use 2 digit years.
Note there is a "feature" in the DATETIME format such that to get the 18 character string in style DDMONYYYY:HH:MM:SS with 4 digits for the year you must use a width of 19 in the format specification. DATETIME19. If you use DATETIME18 you get just the 16 character string with only two digits for year like in your example.
Hi,
since you are using it in Proc SQL you can do it like this:
%let date_start=29JAN16:11:07:33;
%let date_start_new="&date_start."dt;
Bart
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.