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.)));

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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