BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

May I request someone to tell me when we should put a period(.) while calling a macro variable? In some cases, macro variable will get resolved if we just put ampersand (e.g. &test) and in other cases we need to put a period (e.g.&test. ).

 

Thanks for any advise you offer me!

10 REPLIES 10
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, the SAS language will allow you to not put the period after a macro variable where it can clearly still identifiy the end of macro variable, e.g. a space.  Whilst this is possible I would strongly advise against doing it this way.  In my opionion nowadays, code readbility is far more important that saving a character space.  Code layout - e.g. indetations, well formed code - i.e. finisihng macro variable with period, finishing steps with run; or quit;, consistent casing - i.e. all code in lower case unless needed etc. will make your code far more readable.  If you ever have to pick up someone else's code you will know what I mean.  Long gone are the days where text space is limited and saving a tiny fraction of a second is more important than being able to maintain programs and keep transparancy on the code.

 

So TL;DR, in my opinion always use a period.  

Babloo
Rhodochrosite | Level 12

Thanks for your advise!

 

What would be the best example where I should use period and should not use period while resolving macro variable?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Thats really my point, there should never be an instance where you wouldn't put the period in.  Its not special functionality or anything, just laziness and sloppy coding.  Always put the period in.

Reeza
Super User

Some examples of when it are needed, when the text needs a period. Since the period is attached to the macro variable you need two periods:

%let test=Macro Variable;
%put This macro variable has a period &test..;

%put How do I know whats text and whats my &test if it forms part of a file path?;
%put Path = "C:/temp/&testSaved.txt";
%put Path = "C:/temp/&test.Saved.txt";


The documentation also explains this fairly well.

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a001071889.htm

Babloo
Rhodochrosite | Level 12

Thanks for your example.

 

Since I don't have SAS enviornment to execute your code, may I know why you have placed two periods in following put statement? Won't it get resolved if you place one period?

 

%put This macro variable has a period &test..;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

%put This macro variable has a period &test..;

The first period after test shows that the macro variable finishes, the second period is just plain text.  So assume test has the value "too", then it resolves to:
%put This macro variable has a period too.;

Babloo
Rhodochrosite | Level 12

Thanks for your explanation.

 

What if the macro variable test has a value (numeric) "1". Do we still want to put two periods like below while resolving?

 

%put This macro variable has a period &test..;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

What do you want the ouput to look like?  If you set test to be "1" - remember all macro variables are text, then the put statement resolves to:

%put This macro variable has a period 1.;

 

 

Ksharp
Super User
"May I request someone to tell me when we should put a period(.) while calling a macro variable?"
Always. Put period after macro variable is always right.
Reeza
Super User
You can download SASUE to learn on.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 10 replies
  • 1065 views
  • 7 likes
  • 4 in conversation