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

Hello team,

I have a Macro as below:

%MACRO a(text=);
%put %str(N)OTE: &param. &text.!;
%MEND a;

%MACRO b(param=);
%if %lowcase(&param.) eq hello %then %a(text=Dear);
%MEND b;
%b(param=HelLO);

----

I am trying to define the components of this Macro for myself:

Is "a" in %Macro a name of the Macro?

Is (text) in a(text) a parameter for Macro a?

Is %put a Macro statement which writes the result of the Macro into the log?

Is %str a Macro statement which masks parentheses?

Are &Param and &Text a call to the parameters param and text?

Why do we have . and exclamation sign in this code: %put %str(N)OTE: &param. &text.!;?

Why difference did it make if enter (N)OTE as Note? Do we want to show the implementation of STR function?

Does SAS process the code line by line?

If you have more input about this piece of code, please explain it.

Respectfully,

Blue Sky

 

Blue Blue
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

In the macro processor the . indicates the end of a macro variable name or "concatenate" sort of operator for a macro variable followed by other text in the macro language.

The ! is punctuation to display at the end the end of sentence.

 

You might see why the . is needed if you run:

 

%let text=ABC;
%put Test 1: &text123;
%put Test 2: &text.123;

The first %put generates an error because "text123" could be a valid macro variable name but not currently defined (most likely). The second tells SAS to place the digits "123" immediately after the value of the macro variable.

 

This is why when you use macro variables to reference libraries you see two . between the library reference and the data set name such as :

Proc print data=&maclib..&macdatasetname. The first dot ends the library name and the second dot is the typical separator between library and data set.

 

 

 

View solution in original post

3 REPLIES 3
ballardw
Super User

In the macro processor the . indicates the end of a macro variable name or "concatenate" sort of operator for a macro variable followed by other text in the macro language.

The ! is punctuation to display at the end the end of sentence.

 

You might see why the . is needed if you run:

 

%let text=ABC;
%put Test 1: &text123;
%put Test 2: &text.123;

The first %put generates an error because "text123" could be a valid macro variable name but not currently defined (most likely). The second tells SAS to place the digits "123" immediately after the value of the macro variable.

 

This is why when you use macro variables to reference libraries you see two . between the library reference and the data set name such as :

Proc print data=&maclib..&macdatasetname. The first dot ends the library name and the second dot is the typical separator between library and data set.

 

 

 

Reeza
Super User
Are you finding the Macro documentation unhelpful in answering these questions? it seems pretty straightforward to answer questions such as your third one: Is %put a Macro statement which writes the result of the Macro into the log?

%PUT Macro Statement
Writes text or macro variable information to the SAS log.

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n189qvy83pmkt6n1bq2mmwtyb4oe.htm

GN0001
Barite | Level 11
Yes, I got what I wanted by referring to this link.
Regards,
Blue Sky
Blue Blue

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
  • 3 replies
  • 574 views
  • 2 likes
  • 3 in conversation