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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Julie4435637
Obsidian | Level 7

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

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20
%let str=%sysfunc(intnx(quarter,%sysfunc(intnx(quarter, '01JAN2017'd, 5, sameday)), 3, end),mmddyy10.);

%put &str;
novinosrin
Tourmaline | Level 20

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

Julie4435637
Obsidian | Level 7

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

novinosrin
Tourmaline | Level 20

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

 

ballardw
Super User

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.

pb82477
Fluorite | Level 6

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;

 

 

Obs         mydt1            mydt2
103/31/201912/31/2019

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 7 replies
  • 1437 views
  • 0 likes
  • 4 in conversation