Hello
User define a macro variable YYYYMMDD and I want that another macro variable called DDMMYYYY will be created automatically.
For example:
%let YYYYMMDD=20210719;
so DDMMYYYY should be 19072021
What is the way to do it please via %let ?
I know to do it via data step.
What is the reason that I must use compress function ?(Otherwise it is not working well)
Why the macro variable that is created via %LET is not compressed?
%let YYYYMMDD=20210628
Data tt;
dd=substr(compress(&YYYYMMDD.),7,2);/**want to get 28**/
mm=substr(compress(&YYYYMMDD.),5,2);/**want to get 06**/
yyyy=substr(compress(&YYYYMMDD),1,4);/**want to get 2021**/
DDMMYYYY=CATS(dd,mm,yyyy);
call symputx('DDMMYYYY',DDMMYYYY);
Run;
%put &DDMMYYYY.;
I would not do this in a %let statement, all those %sysfunc-calls will make the code hardly readable.
data _null_;
call symputx('DDMMYYYY', put(input("&yyyymmdd.", yymmdd10.), ddmmyyn8.));
run;
%put &=DDMMYYYY.;
1) yymmdd10 was a mistake, working but the "10" should be changed to "8". I quoted the macro-variable to avoid the following notes, which are in-fact error:
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
72:1
NOTE: Invalid argument to function INPUT at Zeile 72 Spalte 33.
2) Try it with ddmmyy8. - you will see the difference.
3) Try it 😉
Well, after actually thinking - should do this more often before i answer - there is only one %sysfunc necessary:
%let DDMMYYYY = %sysfunc(inputn(&yyyymmdd., yymmdd8.), ddmmyyn8.);
%put &=DDMMYYYY;
You could just use the %substr() function. One line of code, no data step required,
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.