Hi All,
I want to create macro variable, Any better way to do.
For example
My macro variable data look like :20oct1997 , but i want to create a new macro variable which look like : 20 OCT 1997
this my approach:
%let dt=20oct1997;
data _null_;
sdt="%upcase(&dt)";
newdt=cat(substr(sdt,1,2),' ',substr(sdt,3,3),' ',substr(sdt,length(sdt)-3,4));
call symputx("newdt",newdt);
run;
%put &newdt;
Thanks
Sam
Perhaps it is easier to see if you don't think about it as a date?
%let old=123456789;
%let new=%substr(&old,1,2) %substr(&old,3,3) %substr(&old,6);
%put "&new";
"12 345 6789"
%let old=20oct1997;
%let new=%upcase(%substr(&old,1,2) %substr(&old,3,3) %substr(&old,6));
%put "&new";
"20 OCT 1997"
Perhaps it is easier to see if you don't think about it as a date?
%let old=123456789;
%let new=%substr(&old,1,2) %substr(&old,3,3) %substr(&old,6);
%put "&new";
"12 345 6789"
%let old=20oct1997;
%let new=%upcase(%substr(&old,1,2) %substr(&old,3,3) %substr(&old,6));
%put "&new";
"20 OCT 1997"
If you are always performing this on dates, then you can use a custom picture format to display the dates the way you want.
proc format;
picture spaced_dt
(default=11)
other = '%0d %b %Y'
(datatype=date)
;
run;
%let dt = 20oct1997;
%put %sysfunc(putn("&dt."d, spaced_dt.));
Sometimes the question becomes why you need to do that? AND how did the date get into the first macro variable? AND will we need Macro variable at all?
%let dt=20oct1997;
%let newdt=%sysfunc(prxchange(s/(\d{2})(\w+)(\d{4})/$1 \U$2 $3/i,-1,&dt));
%put &newdt;
Thank you All,
I agree with you Hai.kuo. while i am practicing with macro variables with date character variable. i got a question if we need to keep space between the date, how should i achieve it. i tried one approach i am looking for better one.. so i posted on forum. i want to learn different approach , from SAS Guru 's on this forum.
Thanks
Sam
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.