08-14-2014 09:53 PM
%let var=chicago, 1;
var='new york, 2';
which one of the following explains why the program fails to execute?
A. The %STR() is invalid syntax;
B. The %scan function does not exist.
C. The %scan function has too many arguments.
D. The macro variable VAR does not get created properly.
The answer is C.
Do you guys know how to avoid this problem. Is this problem raised by too many parentheses?
Thank you guys!s
08-14-2014 10:11 PM
Actually, it executes but you end up with an unitialized variable named Chicago.
It's hard to see what you are trying to do. And don't know why you would specify a null %str() as the delimiter for scan.
If you are concerned that the comma in the value of &var will be seen as a delimiter to %scan(), one solution is to macro quote it (mask it):
70 %let var=%str(chicago, 1) ; 71 %put %scan(&var,1,%str( )) ; chicago, 72 %put %scan(&var,2,%str( )) ; 1
08-14-2014 10:25 PM
becomes after replacing &var
Now it has too many arguments and taking chicago as variable to scan as a result generating a message unitialized variable named Chicago
08-15-2014 02:06 AM
This OP is trying to learn SAS by understanding some questions. He can run the code himself and see what is doing.
Setting the trace/debug options will show you what is happening.
08-15-2014 07:27 AM
This question was written before %SCAN was enhanced to include a 4 argument. Answer C no longer applies.
%SCAN(argument, n<,charlist <,modifiers> >)
08-15-2014 07:38 AM
agree and remind the releases/versions they are the one making a release upgrade sometimes surprising.
8.2 is at: Macro Language Dictionary : %SCAN and %QSCAN
08-15-2014 11:31 AM
Excellent blog post today by Russ Tyndall covering macro quoting. Recommended reading for everyone who has struggled with it. That is to say, everyone who has used it.
Amazed that he can cover so much, so clearly, in a blog post rather than a full paper or book chapter. I plan to link to it often whenever macro quoting comes up in the forums...
08-16-2014 08:15 AM
Xia, I disagree on that there are too many secrets in sas-macro. It is well documented as a fundamental: SAS(R) 9.4 Macro Language: Reference, Second Edition. The mixing up of several used language in some piece of coding is confusing.
For al long time seeing this happening. even the usage of /* * / can be troublesome. Code that starting in position 1 for a mainframe instream. The SAS- comment is not seen as SAS but the mainframe sees end-of-job. The person doing this blamed SAS for not having solved that.
Tokens words are documented at: SAS(R) 9.4 Macro Language: Reference, Second Edition (macro language)
There is something strange on macrocomments. See SAS(R) 9.4 Macro Language: Reference, Second Edition and the semicolon usage.
As it is a concept missing in many other languages it is often badly understood. It is text-processing changing the SAS code before that gets interpreted (compiled) and executed on intermediate boundaries. The word "macro-processing" is often used in a different approach with other languages.
08-16-2014 08:56 AM
Yeah, Macro documentation is very good . and it is very heavy . You need lots of time to digest it . and Sometime you gonna find why it can't happen, I am doing the same thing as documentation did . In reality , there are too many stories about it when I am coding sas macro . the basic concept about macro is how and when to use these special quote macro function ( %str %nrstr %quote %unquote %bquote %nrbquote %superq ...) like Quentin did . Quentin refer to a very good paper which we can start from it . and don't forget the interface between Macro Device and Data Step like call execute() symget() symput() symputx() resolve() ............. specially call execute() , you will get many confusion when you are using it . anyway, I still think there are too many things we need to learn about Macro . That is my opinion. Don't be offend . Jaap.
08-16-2014 10:04 AM
Xia, no problem. I did the technical support and wanting it as easy as possible for SAS-users. Eliminating as much as possible of the differences Windows/Unix/Mainframe. Supporting libnames/filenames options being eliminated form application code (DTAP). Offering standard time window selections.
I only could do that using SAS-macros (history backed to V6). Seen a lot of that with all kind of change management challenges.
Indeed, the macro part is together with some other thing the most important one to do this kind of things. Always learning more.
Several issues experienced a/ IT people of OS level vision did not like SAS. b/ SAS people did not do not like that also although it was a consequence of mandatory regulator guidelines and in house policies. c/ no internal support within the IT organization supporting the business (mistake 10).
http://www.cio.com/article/2464167/business-intelligence/9-common-bi-software-mistakes-and-how-to-av... Is see them back as 3,4,7 no 10 to be added. These are the thing I mostly quickly react on, its off the shelf knowledge.
08-17-2014 08:12 AM
I think we both are in different SAS field . You are more interesting with SAS Administrator ,OS , hardware ....... I am more interesting with SAS statistical stuff which is most valuable thing for SAS I think . The common thing is we all need to write SAS code to finish our job . right ? If I have some time in the future, I will be happy to learn some stuff in SAS Administrator field like BI, DI, BShell / CShell script ,OS Command .......... SAS is so huge , you can learn it all in your lifetime .
08-17-2014 08:47 AM
Xia, I am interested in both worlds including statistics. You cannot segregate them as it is very related to each other. Yes writing SAS code is doing something to finish a task. The link of BI I gave is about optimizing work that is a more generic level, not about just coding statistics. It is about business goals/efficiency/alignment. You can do as nice coding and analytics as you like, when there is no value it is just playing-time.
Being not aligned at that level is the worst thing that can happen, no matter how nice your analytics as tool or your presentation could be.
Yes SAS is so huge you can learn all the time. More amazingly a lot of different lines:
- there are approaches coding techniques are irrelevant (solution-lines) still needing some coding.
- Moving to server based processing abandoning SAS-pc and Still seeing a lot new coming out.
- Analytics part getting automated look at Eminer and VA (doing decision trees and forecasting) and other parts to get more details on the specific procedures. This could be becoming an area were the skills coding statistics will become less relevant. The new pony-trick with solutions.
In this thread we are trying to help someone starting understanding some of it. I am guessing someone doing a basic study.
No need to be angry on each other or place him or me in an isolated area.