I've the macro variable as below. Now I want to create one more macro variable by using this macro variable 'Meta_Col' and I want to add the string meta. to the value in the macro variable Meta_Col
%let Meta_Col=businessDataName,reportingArea,reportingDate,reportingPurpose;
Desired Result is to create one macro variable (e.g. Meta_new_Col) and it should have value as below. Any help?
meta.businessDataName,meta.reportingArea,meta.reportingDate,meta.reportingPurpose
%let Meta_Col=businessDataName,reportingArea,reportingDate,reportingPurpose;
data _null_;
meta_col = "&meta_col.";
length meta_new_col $1000;
do i = 1 to countw(meta_col,",");
meta_new_col = catx(",",meta_new_col,"meta."!!scan(meta_col,i,","));
end;
call symputx("meta_new_col",meta_new_col);
run;
%put &=meta_new_col;
%let Meta_Col=businessDataName,reportingArea,reportingDate,reportingPurpose;
data _null_;
meta_col = "&meta_col.";
length meta_new_col $1000;
do i = 1 to countw(meta_col,",");
meta_new_col = catx(",",meta_new_col,"meta."!!scan(meta_col,i,","));
end;
call symputx("meta_new_col",meta_new_col);
run;
%put &=meta_new_col;
Alternatively, you can use a combination of functions:
%let Meta_new_Col=meta.%sysfunc(tranwrd(%quote(&meta_col),%str(,),%str(,meta.)));
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.