I have a macro date which I am trying to convert to a yymmn6. format. ie."201707"
It seems simple enough.
%let dte = 07072017;
%let dte_9 = %sysfunc(inputn(&dte,ddmmyyyyn8.),yymonn7.);
%put &dte_9;
7072017
when I use yymonn7. as the format for the %sysfunc I get "7072017"
But when I change the format to yymmn6. I get Jibberish.
%let dte = 07072017;
%let dte_9 = %sysfunc(inputn(&dte,ddmmyyyyn8.),yymmn6.);
%put &dte_9;
******
Why is the date outputted as * ? What can I do to get the date of "201707" ?
First, your input format (ddmmyyyyn8.) is wrong. The statement
%let x=%sysfunc(inputn(07072017,ddmmyyyyn8.));
produces the message
WARNING: Argument 2 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
So
%let dte_9=%substr(%sysfunc(inputn(&dte,ddmmyy8.),yymmddn8.),1,6);
%put &=dte_9;
Note that the YYMON format issue an abbreviated month NAME, not month NUMBER.
Have you tried it the easy (but untested) way?
%let dte = 07072017;
%let dte_9 = %substr(&dte, 3, 6);
I tried
%let dte_9 = %substr(&dte,3,6);
%put &dte_9;
072017
Which seems to work, but the date format is "072017".
How would I then transform it to YYYYMM as "201707"?
I tried
%let dte_10 = %sysfunc(inputn(&dte_9,mmyyn6.),yymonn6.);
%put &dte_10;
72017
But the leading zero is gone and the date format is mYYYY.
OK, take two pieces of it then:
%let dte = 07072017;
%let dte_9 = %substr(&dte, 5, 4)%substr(&dte, 3, 2);
Just don't add a space before the second instance of %SUBSTR.
First, your input format (ddmmyyyyn8.) is wrong. The statement
%let x=%sysfunc(inputn(07072017,ddmmyyyyn8.));
produces the message
WARNING: Argument 2 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is out of range.
So
%let dte_9=%substr(%sysfunc(inputn(&dte,ddmmyy8.),yymmddn8.),1,6);
%put &=dte_9;
Note that the YYMON format issue an abbreviated month NAME, not month NUMBER.
Thanks mkeintz & Astounding,
Much appreciated.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.