BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
makset
Obsidian | Level 7

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@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;

 

 

--
Paige Miller

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
makset
Obsidian | Level 7

@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

 

makset
Obsidian | Level 7
DTCut = 1976486399
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller
makset
Obsidian | Level 7

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

 

 

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
makset
Obsidian | Level 7

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"

PaigeMiller
Diamond | Level 26

@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;

 

 

--
Paige Miller
makset
Obsidian | Level 7

And that's it
Thank you
Respect

Tom
Super User Tom
Super User

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?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 10 replies
  • 1173 views
  • 0 likes
  • 3 in conversation