DATA Step, Macro, Functions and more

how to achieve variable-name modification in a macro?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 99
Accepted Solution

how to achieve variable-name modification in a macro?


I have

%inseg10(wu1.custbase2m,work.T8_1a,'N',SA,SAP,'IN1');

%macro inseg10(dsin,dsout,ntb,product1,product2,custclass);

in fact product2=product1||'P';*variable name in a data set ,for eg     SA,SAP;

I tried debug in macro inseg10:

%put &product1||'P';

%put &product1||P;

neither output is what I wanted as below

SAP;

How can I use statement in macro using & product1 to constitute product2?

THANKS.


Accepted Solutions
Solution
‎04-16-2012 11:08 AM
Super User
Super User
Posts: 7,060

Re: how to achieve variable-name modification in a macro?

To SAS macro code everything is a string. So if you have a macro variable called PRODUCT1 with the value SA and you want to use it to refer to variables SA and SAP in the actual SAS code that the macro will generate you do not need any concatenation characters.  What you need is to use a period to tell SAS not to look for a macro variable named PRODUCT1P.

proc means ;

  var &product1 &product1.p ;

run;

View solution in original post


All Replies
Respected Advisor
Posts: 4,173

Re: how to achieve variable-name modification in a macro?

Also considering your other thread around this macro (https://communities.sas.com/message/123512#123512) you probabely should give us the full code and also tell us what you have, what you want and what problem you really want to solve.

In my experience a lot of people at a certain stage in their "SAS skills development" tend to overuse macro coding and to forget about simple SAS datastep aproaches. Consider that you should try to write code which you still can easily understand in 6 months time.

Frequent Contributor
Posts: 99

Re: how to achieve variable-name modification in a macro?


patrick,

You are absolutely right. I am on my first time writing macro while with only 4 months experience of SAS.

thanks for your guiding. I will go on.

dawn.

Solution
‎04-16-2012 11:08 AM
Super User
Super User
Posts: 7,060

Re: how to achieve variable-name modification in a macro?

To SAS macro code everything is a string. So if you have a macro variable called PRODUCT1 with the value SA and you want to use it to refer to variables SA and SAP in the actual SAS code that the macro will generate you do not need any concatenation characters.  What you need is to use a period to tell SAS not to look for a macro variable named PRODUCT1P.

proc means ;

  var &product1 &product1.p ;

run;

Frequent Contributor
Posts: 99

Re: how to achieve variable-name modification in a macro?

Tom,Thanks for your patient explantion. It works. Dawn

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 225 views
  • 3 likes
  • 3 in conversation