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!
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.
Thanks for your advise!
What would be the best example where I should use period and should not use period while resolving macro variable?
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.
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
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..;
%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.;
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..;
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.;
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!
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.