BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
David_Billa
Rhodochrosite | Level 12

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
%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;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User
%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;
FreelanceReinh
Jade | Level 19

Alternatively, you can use a combination of functions:

%let Meta_new_Col=meta.%sysfunc(tranwrd(%quote(&meta_col),%str(,),%str(,meta.)));

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 934 views
  • 2 likes
  • 3 in conversation