Need to create a date variable based on another date variable formatted mmddyy8.
Code below is supposed to create a date of the first day of the quarter of whatever date the variable "dtip" is.
No matter what I try, date always is numeric, not formatted mmddyy8.
CODE:
%global q_start ;
*/first date of the quarter of whatever DTIP is assgined;
data _null_;
dtip = '01MAR26'd;
Q_start=intnx('quarter',dtip, -0);
call symputx('Q_Start',Q_start);
call symputx('dtip',dtip);
format Q_start mmddyy8.;
format DTIP mmddyy8.;
run;
%macro pqr();
%put &dtip;
%put &q_start;
%mend;
%pqr;
LOG:
5 */first date of the quarter of whatever DTIP is assgined;
6 data _null_;
7 dtip = '01MAR26'd;
8 Q_start=intnx('quarter',dtip, -0);
9 call symputx('Q_Start',Q_start);
10 call symputx('dtip',dtip);
11 format Q_start mmddyy8.;
12 format DTIP mmddyy8.;
13 run;
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.03 seconds
14 %macro pqr();
15 %put &dtip;
16 %put &q_start;
17 %mend;
18 %pqr;
-12359 <-need this value formatted mmddyy8.
-12418 <-need this value formatted mmddyy8.
THANX
You are already attaching the MMDDYY8. format to your new VARIABLEs.
Do you mean the MACRO VARIABLEs your data step is also creating? You cannot attach any formats to a macro variable. They are just strings. But you can tell SAS to use the MMDDYY8. format specification to generate the string that is stored in the macro variable.
call symputx('Q_Start',put(Q_start,mmddyy8.));
call symputx('dtip',put(dtip,mmddyy8.));
Why do you need macro variables in that MMDDYYYY style?
What are you going to use the macro variables for?
You cannot use them as dates. And they will be confusing if used to generate title strings or parts of filenames.
You need VVALUE function.
58 %global q_start ;
59
60 */first date of the quarter of whatever DTIP is assgined;
61 data _null_;
62 dtip = '01MAR26'd;
63 Q_start=intnx('quarter',dtip, -0);
64 call symputx('Q_Start',vvalue(Q_start));
65 call symputx('dtip',vvalue(dtip));
66 format Q_start mmddyy8.;
67 format DTIP mmddyy8.;
68 run;
69
70 %put NOTE: &=dtip;
NOTE: DTIP=03/01/26
71 %put NOTE: &=q_start;
NOTE: Q_START=01/01/26
CALL SYMPUTX treats its arguments as expressions, and these do not automatically apply formats.
Either use VVALUE, as already suggested, or the PUT function with a suitable format.
You are already attaching the MMDDYY8. format to your new VARIABLEs.
Do you mean the MACRO VARIABLEs your data step is also creating? You cannot attach any formats to a macro variable. They are just strings. But you can tell SAS to use the MMDDYY8. format specification to generate the string that is stored in the macro variable.
call symputx('Q_Start',put(Q_start,mmddyy8.));
call symputx('dtip',put(dtip,mmddyy8.));
Why do you need macro variables in that MMDDYYYY style?
What are you going to use the macro variables for?
You cannot use them as dates. And they will be confusing if used to generate title strings or parts of filenames.
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →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.
Ready to level-up your skills? Choose your own adventure.