Hello
I can change the standard dt to a number
%let DTCut = "18&M8.2022:23:59:59"dt; %put DTCut = %sysfunc(inputn(&DTCut.,anydtdtm.));
but I can't handle it
proc format; picture DTCustom other = '%Y-%0m-%0d-%0H-%0M-%0S' (datatype = datetime); run; %let DTCut = "2022-08-18-23-59-59";
Thank you for your answer.
Best regards.
@makset wrote:
from this:
%let m8=Aug; %let dtcut = %sysevalf("18&m8.2022:23:59:59"dt); %put &=dtcut;
Yes, the code I provided works.
not this:
%let dtcut = %sysevalf("2022-08-18-23-59-59"dt); %put &=dtcut;
ERROR: Unknown %SYSEVALF conversion operand 'DTCUSTOM.' specified; conversion is terminated.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: putn("2022-08-18-23-59-59"
No one ever said this would work. It doesn't work because "2022-08-18-23-59-59"dt
is not recognized anywhere in SAS as valid code. Only date/time literals like this will work: "18aug2022:23:59:59"dt, the appearance must be that exactly, except the the letters can be mixed case or upper case. Your date time value is not that appearance, so SAS will not recognize it and can't use it.
However, this works:
%let dtcut = %sysfunc(inputn(2022-08-18-23-59-59,anydtdtm.));
%put &=dtcut;
@makset wrote:
I can change the standard dt to a number
%let DTCut = "18&M8.2022:23:59:59"dt;
I don't think anyone knows what macro variable &M8 is and without that we can't help you.
In addition, its not clear to me the desired output (or even the inputs) are that you are struggling with. Please explain the problem in more detail.
@PaigeMiller wrote:
@makset wrote:
I can change the standard dt to a number
%let DTCut = "18&M8.2022:23:59:59"dt;I don't think anyone knows what macro variable &M8 is and without that we can't help you.
In addition, its not clear to me the desired output (or even the inputs) are that you are struggling with. Please explain the problem in more detail.
%let M1 = jan; %let M2 = feb; %let M3 = mar; %let M4 = apr; %let M5 = may; %let M6 = jun; %let M7 = jul; %let M8 = aug; %let M9 = sep; %let M10 = oct; %let M11 = nov; %let M12 = dec;
sorry, I didn't notice that
Is this what you want to do?
proc format;
picture DTCustom other = '%Y-%0m-%0d-%0H-%0M-%0S' (datatype = datetime);
run;
%let m8=Aug;
%let dtcut = %sysevalf("18&m8.2022:23:59:59"dt);
%put &=dtcut;
%let dtcut1= %sysfunc(putn(&dtCut,dtcustom.));
%put &=dtcut1;
I have it"
%let DTCut = "2022-08-18-23-59-59";
or
%let DTCut = "2022-08-18-23-59-59"dt;
I want this:
DTCut = 1976486399
sorry for the confusion
@makset wrote:
I have it"
%let DTCut = "2022-08-18-23-59-59";
or
%let DTCut = "2022-08-18-23-59-59"dt;I want this:
DTCut = 1976486399
sorry for the confusion
My earlier code produces this exact result.
from this:
%let m8=Aug;
%let dtcut = %sysevalf("18&m8.2022:23:59:59"dt);
%put &=dtcut;
not this:
%let dtcut = %sysevalf("2022-08-18-23-59-59"dt);
%put &=dtcut;
ERROR: Unknown %SYSEVALF conversion operand 'DTCUSTOM.' specified; conversion is terminated.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: putn("2022-08-18-23-59-59"
@makset wrote:
from this:
%let m8=Aug; %let dtcut = %sysevalf("18&m8.2022:23:59:59"dt); %put &=dtcut;
Yes, the code I provided works.
not this:
%let dtcut = %sysevalf("2022-08-18-23-59-59"dt); %put &=dtcut;
ERROR: Unknown %SYSEVALF conversion operand 'DTCUSTOM.' specified; conversion is terminated.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: putn("2022-08-18-23-59-59"
No one ever said this would work. It doesn't work because "2022-08-18-23-59-59"dt
is not recognized anywhere in SAS as valid code. Only date/time literals like this will work: "18aug2022:23:59:59"dt, the appearance must be that exactly, except the the letters can be mixed case or upper case. Your date time value is not that appearance, so SAS will not recognize it and can't use it.
However, this works:
%let dtcut = %sysfunc(inputn(2022-08-18-23-59-59,anydtdtm.));
%put &=dtcut;
And that's it
Thank you
Respect
The request doesn't make much sense.
You appear to be starting with a DATETIME value, which is already a NUMBER. The number of seconds since start of 1960.
So what is it you want to produce?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.