BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Babloo
Rhodochrosite | Level 12

 

I ran the following program and got the error as below. Appreciate if someone of you guide me to get the desired output.

 

%macro test;
%let sysparm=D20181207:00:00:00*N*N ;
%let glb_runcode = %substr(&sysparm,2,8);
%put glb_runcode = &glb_runcode ; 
%let glb_runcode_date=%sysfunc(inputn(&glb_runcode,date9.));
%put glb_runcode_date = &glb_runcode_date ; 
%mend;

%test;
4         %macro test;
25         %let sysparm=D20181207:00:00:00*N*N ;
26         %let glb_runcode = %substr(&sysparm,2,8);
27         %put glb_runcode = &glb_runcode ;
28         %let glb_runcode_date=%sysfunc(inputn(&glb_runcode,date9.));
29         %put glb_runcode_date = &glb_runcode_date ;
30         %mend;
31         
32         %test;
glb_runcode = 20181207
WARNING: Argument 1 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The result of the operations have been set 
      to a missing value.

Desired Output:

 

glb_runcode_date = 7dec2018

1 ACCEPTED SOLUTION

Accepted Solutions
ShiroAmada
Lapis Lazuli | Level 10

Try this..

%macro test;
%let sysparm=D20181207:00:00:00*N*N ;
%let glb_runcode = %substr(&sysparm,2,8);
%put glb_runcode = &glb_runcode ; 
%let glb_runcode_date=%sysfunc(inputn(&glb_runcode,yymmdd8.), date9.);
%put glb_runcode_date = &glb_runcode_date ; 
%mend;

%test;

View solution in original post

2 REPLIES 2
ShiroAmada
Lapis Lazuli | Level 10

Try this..

%macro test;
%let sysparm=D20181207:00:00:00*N*N ;
%let glb_runcode = %substr(&sysparm,2,8);
%put glb_runcode = &glb_runcode ; 
%let glb_runcode_date=%sysfunc(inputn(&glb_runcode,yymmdd8.), date9.);
%put glb_runcode_date = &glb_runcode_date ; 
%mend;

%test;
Kurt_Bremser
Super User

You are extracting 8 bytes with the substr(), but use a format that has a default length of 9. That alone should get you to thinking.

And then you should READ THE DOCUMENTATION (section date and time) of the formats, so you see which one to use. DO IT NOW. It is not rocket science, and it won't make your brain explode. Promise.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1255 views
  • 2 likes
  • 3 in conversation