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
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;
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;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.