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


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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

4 REPLIES 4
Patrick
Opal | Level 21

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.

bbb_NG
Fluorite | Level 6


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.

Tom
Super User Tom
Super User

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;

bbb_NG
Fluorite | Level 6

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 4 replies
  • 823 views
  • 3 likes
  • 3 in conversation