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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 2 replies
  • 763 views
  • 2 likes
  • 3 in conversation