Hello, I am trying to format the value of &str (which resolves to 21639) below. I have tried various inputc, putc, inputn, putn variations but can't seem to come up with a macro variable with the value of 12/31/2019.
code below ****************************
%let str=intnx('quarter',intnx('quarter', '01JAN2017'd, 5, "sameday"), 3, "end");
data _null_;
call symputx('dt', &str,'G');
run;
%put dt=&dt;
* a couple attempts of formatting the value;
data _null_;
call symputx('dt1', %sysfunc(inputn(&str, 6.), mmddyy10.),'G');
call symputx('dt2', %sysfunc(21639,mmddyy10.),'G'));
run;
%put dt1=&dt1;
%put dt2=&dt2;
log **************************************************
17 %let str=intnx('quarter',intnx('quarter', '01JAN2017'd, 5, "sameday"), 3, "end");
18
19 data _null_;
20 call symputx('dt', &str,'G');
21 run;
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
22
23 %put dt=&dt;
dt=21639
24
25 data _null_;
26 call symputx('dt1', %sysfunc(inputn(&str, 6.), mmddyy10.),'G');
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.
27 call symputx('dt2', %sysfunc(21639,mmddyy10.),'G'));
ERROR: Function name missing in %SYSFUNC or %QSYSFUNC macro function reference.
27 call symputx('dt2', %sysfunc(21639,mmddyy10.),'G'));
_
159
ERROR 159-185: Null parameters for SYMPUTX are invalid.
27 call symputx('dt2', %sysfunc(21639,mmddyy10.),'G'));
_________
386
ERROR 386-185: Expecting an arithmetic expression.
27 call symputx('dt2', %sysfunc(21639,mmddyy10.),'G'));
_________
201
2 The SAS System 10:40 Wednesday, June 27, 2018
ERROR 201-322: The option is not recognized and will be ignored.
27 call symputx('dt2', %sysfunc(21639,mmddyy10.),'G'));
_________
76
ERROR 76-322: Syntax error, statement will be ignored.
28
29 run;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
30
31 %put dt1=&dt1;
dt1=.
32 %put dt2=&dt2;
dt2=0.0000479317
33
34
You are right - the statement was more complicated than it needed to be. I did shorten it and tried it out. Why do I get different results when I assign the value to the macro variable using a symput vs %let?
%let str=%sysfunc(intnx(quarter, '01JAN2017'd, 8, end),mmddyy10.);
data _null_;
call symput('dt1',&str);
run;
%put &dt1;
%let dt2=&str;
%put &dt2;
log ***************
17 %let str=%sysfunc(intnx(quarter, '01JAN2017'd, 8, end),mmddyy10.);
18
19 data _null_;
20 call symput('dt1',&str);
21 run;
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
20:6
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
22 %put &dt1;
0.0000479317
23
24 %let dt2=&str;
25 %put &dt2;
03/31/2019
%let str=%sysfunc(intnx(quarter,%sysfunc(intnx(quarter, '01JAN2017'd, 5, sameday)), 3, end),mmddyy10.);
%put &str;
Also just wondering the purpose of such long expression?
Coz the below two produces the same result-->
/*lenghty version*/
%let str=%sysfunc(intnx(quarter,%sysfunc(intnx(quarter, '01JAN2017'd, 5, sameday)), 3, end),mmddyy10.);
%put &str;
/*short version*/
%let k=%sysfunc(intnx(quarter, '01JAN2017'd, 8, end),mmddyy10.);
%put &k;
Log:
753 /*lenghty version*/
754 %let str=%sysfunc(intnx(quarter,%sysfunc(intnx(quarter, '01JAN2017'd,
754! 5, sameday)), 3, end),mmddyy10.);
755
756 %put &str;
03/31/2019
757 /*short version*/
758 %let k=%sysfunc(intnx(quarter, '01JAN2017'd, 8, end),mmddyy10.);
759 %put &k;
03/31/2019
You are right - the statement was more complicated than it needed to be. I did shorten it and tried it out. Why do I get different results when I assign the value to the macro variable using a symput vs %let?
%let str=%sysfunc(intnx(quarter, '01JAN2017'd, 8, end),mmddyy10.);
data _null_;
call symput('dt1',&str);
run;
%put &dt1;
%let dt2=&str;
%put &dt2;
log ***************
17 %let str=%sysfunc(intnx(quarter, '01JAN2017'd, 8, end),mmddyy10.);
18
19 data _null_;
20 call symput('dt1',&str);
21 run;
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
20:6
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
22 %put &dt1;
0.0000479317
23
24 %let dt2=&str;
25 %put &dt2;
03/31/2019
because you missed the double quotes in the call symput statement
%let str=%sysfunc(intnx(quarter, '01JAN2017'd, 8, end),mmddyy10.);
data _null_;
call symput('dt1',"&str");
run;
%put &dt1;
Log:
786 %let str=%sysfunc(intnx(quarter, '01JAN2017'd, 8, end),mmddyy10.);
787
788 data _null_;
789 call symput('dt1',"&str");
790 run;
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
791 %put &dt1;
03/31/2019
Is there an actual reason to use the double intnx instead of
intnx('quarter', '01JAN2017'd, 8, "end");
If you are using some other parameters it might be better to just add them instead of that double intnx.
It might be needed if you were using different intervals but calendar quarter is a calendar quarter and end will be the same.
Julie, a value of 21639 converts to day 03/31/2019. It appears that your "%let str" statement might need a value of 6 in the outer intnx call which will provide a value of 21914 and will resolve to 12/31/2019.
My code isn't pretty, but I think it illustrates the concept adequately.
options symbolgen;
%let str1=intnx('quarter',intnx('quarter', '01JAN2017'd, 5, "sameday"), 3, "end");
%let str2=intnx('quarter',intnx('quarter', '01JAN2017'd, 5, "sameday"), 6, "end");
data _null_;
call symputx('dt1', &str1,'G');
call symputx('dt2', &str2,'G');
run;
data temp;
format mydt1 mydt2 mmddyy10.;
mydt1=&dt1;
mydt2=&dt2;
run;
%put _all_;
proc print;run;
1 | 03/31/2019 | 12/31/2019 |
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.