SAS code stops running after submit, nothing in log either - sas

I am writing a SAS program which also uses some macros. However, SAS suddenly stopped running the codes that I submitted. If I select and submit a part of the code, I can see it copied in the log but that's it. No note, error or warning. Neither is the code executed. Doesn't matter if the code is a simple data step without any macro variables.
Am I missing anything? What should I check or verify?

This sounds like a classic case of unbalanced quotes within one of your macros. Running the code below should clear it, then you will need to check the code for the error.
*); */; /*’*/ /*”*/; %mend;

This same problem happened with me during macro coding except it was unmatched parentheses. Original line of problem code was
"...%then %let DLINE=%str(if (P ge 22 and STAFF eq 0 then STAFF=1;);"
Note unmatched "(" character before P variable. Either removing the "("
or adding ")" after "eq 0" solves problem.

I figure out why I also got this issue.
When I collapse all the macro code ( a temporary one just in the same file of my project code), and rerun it.
SAS actually just run the collapsed part, so it is just the first row of the macro.
The code above solves my problem, but I also need to rerun the expanded macro code again to avoid future error.

Related

SPSS Syntax - IF statements with multiple AND commands

I am trying to recode a variable with an IF statement with 3 x AND conditions within it.
When I run the syntax it doesn't present any errors but the variable has not changed.
Example of Syntax:
IF (((Variable_a =0) AND (Variable_b=0)) AND (Variable_c >0)) Variable_d=9999.
I've tried various combinations of ()s but no joy.
All values in each variable are numerical
Any suggestions of how to overcome this?
EDIT - added an 'execute' command to the end of the code. Unfortunately it still doesn't appear to be work.

SAS ODS escape character macro variable error

The SAS v9.4 documentation lists an automatic macro variable &sysodsescapechar which contains the current ODS escape character, assigned using ods escapechar=.
Whenever I try to view the macro variable using a %put statement, I get the following error:
ERROR: Open code statement recursion detected.
This happens when open code erroneously causes a macro statement to call another macro statement.
I've tried all of the following:
%put &=sysodsescapechar.;
%put %nrbquote(&sysodsescapechar.);
%put %superq(sysodsescapechar);
They all result in the same error.
When I try to view the macro variable using a data step, it appears to be empty.
data test;
esc = "&sysodsescapechar.";
put esc=;
run;
If the macro variable actually is empty, why do I get open code statement recursion errors? The %put statement on its own is valid, so putting an empty variable shouldn't be an issue.
Any guidance here would be much appreciated.
What's happening is the escape char seems to need a close parentheses. For example:
%put %superq(SYSODSESCAPECHAR););
;
It escapes the ) , which means now you have
%put superq(;);
In your first example, it's a little trickier because a semicolon by itself doesn't seem to be escaped so you have to provide a close parentheses:
%put &SYSODSESCAPECHAR.)x;
x
That works, for example. I'm not sure if it's only close paren or other things that would also allow it to stop trying to escape, but that's the only thing I can tell works.
You can look at the actual value of the macro variable in SASHELP.VMACRO; it's not ' ' (which is indeed what gets passed to the data step even with SYMGET, but it's clearly parsed). In that table it is '03'x, which looks like a uppercase L in the upper half of the character. That is the "End of Text" control character. I suspect the behavior in the editor when using this in text (in a macro variable) is simply a behavior of the editor - '03'x is not representable on many editors (if I try to paste it here, for example, it isn't displayed, but does exist as something I can backspace over with zero width). SAS is clearly capable of dealing with a 'normal' ods escapechar but isn't capable of dealing with '03'x in the same fashion.

How to mask potential macro variables as part of a filename URL string

I have written the following filename statement as part of a program to dynamically pull down stock quotes in iterative steps. This now works fine, except for three warning messages I am getting in the log:
1) &s= is not resolved
2) &f= is not resolved
3) Warnings: String is more than 252 characters long, you may have unbalanced quotations
filename loader url "http://finance.yahoo.com/d/quotes.csv?s=&svar1.+&svar2.+&svar3.+&svar4.+&svar5.+&svar6.+&svar7.+&svar8.+&svar9.+&svar10.+
&svar11.+&svar12.+&svar13.+&svar14.+&svar15.+&svar16.+&svar17.+&svar18.+&svar19.+&svar20.+
&svar21.+&svar22.+&svar23.+&svar24.+&svar25.+&svar26.+&svar27.+&svar28.+&svar29.+&svar30.+
&svar31.+&svar32.+&svar33.+&svar34.+&svar35.+&svar36.+&svar37.+&svar38.+&svar39.+&svar40.+
&svar41.+&svar42.+&svar43.+&svar44.+&svar45.+&svar46.+&svar47.+&svar48.+&svar49.+&svar50.+
&svar51.+&svar52.+&svar53.+&svar54.+&svar55.+&svar56.+&svar57.+&svar58.+&svar59.+&svar60.+
&svar61.+&svar62.+&svar63.+&svar64.+&svar65.+&svar66.+&svar67.+&svar68.+&svar69.+&svar70.+
&svar71.+&svar72.+&svar73.+&svar74.+&svar75.+&svar76.+&svar77.+&svar78.+&svar79.+&svar80.+
&svar81.+&svar82.+&svar83.+&svar84.+&svar85.+&svar86.+&svar87.+&svar88.+&svar89.+&svar90.+
&svar91.+&svar92.+&svar93.+&svar94.+&svar95.+&svar96.+&svar97.+&svar98.+&svar99.+&svar100.+
&svar101.+&svar102.+&svar103.+&svar104.+&svar105.+&svar106.+&svar107.+&svar108.+&svar109.+&svar110.+
&svar111.+&svar112.+&svar113.+&svar114.+&svar115.+&svar116.+&svar117.+&svar118.+&svar119.+&svar120.+
&svar121.+&svar122.+&svar123.+&svar124.+&svar125.+&svar126.+&svar127.+&svar128.+&svar129.+&svar130.+
&svar131.+&svar132.+&svar133.+&svar134.+&svar135.+&svar136.+&svar137.+&svar138.+&svar139.+&svar140.+
&svar141.+&svar142.+&svar143.+&svar144.+&svar145.+&svar146.+&svar147.+&svar148.+&svar149.+&svar150.+
&svar151.+&svar152.+&svar153.+&svar154.+&svar155.+&svar156.+&svar157.+&svar158.+&svar159.+&svar160.+
&svar161.+&svar162.+&svar163.+&svar164.+&svar165.+&svar166.+&svar167.+&svar168.+&svar169.+&svar170.+
&svar171.+&svar172.+&svar173.+&svar174.+&svar175.+&svar176.+&svar177.+&svar178.+&svar179.+&svar180.+
&svar181.+&svar182.+&svar183.+&svar184.+&svar185.+&svar186.+&svar187.+&svar188.+&svar189.+&svar190.+
&svar191.+&svar192.+&svar193.+&svar194.+&svar195.+&svar196.+&svar197.+&svar198.+&svar199.+&svar200.
&f=&&fvar&a.";
Firstly, how can I mask the &s= &f= from the processor, but allow it still resolve the &svar macro variables? I have tried various attempts at using %superq and %nrbquote but not had much luck.
Also, is there a way to a mask the warning about the string being long other than using log errors to suppress all options? Ideally I don't want to do that as I would still like to see any new errors that may arise for whatever reason.
Thanks
To turn off the warning about string being too long, use system option NOQUOTELENMAX.
To mask an & that you can see, try %NRSTR(), e.g. %NRSTR(&f).
To "mask" the ampersand so it is not scanned by the macro processor, just use the %STR function. I don't see any reference to an &s variable in the code you show, but I do see one from&f. Change that last parameter to:
%str(&)f=&&fvar&a.
Also, to assist debugging things like this, I strongly suggest that you build the entire string into it's own macro variable (perhaps named url). In other words:
%let url="http://finance.yahoo.com/d/quotes.csv?%str(&)s=//svars// %str(&)f=&&fvar&a.";
%put url=&url;
filename loader url "&url";
I'm guessing that the s= was &s= in the code that had the error and I substituted your long parameter string with //svars// only to save formatting in this answer.
Using a "helper macro variable" like this should help during development. The %put just echos the string during testing and would not be part of the final macro.

Formatting of switch statement

Say I have my cursor position to the right of a right facing case curly brace, like so:
Now, if I press enter, I expect it to auto align the cursor two tabs in, just like the break statement. But what it does is this:
It adds a ridiculous five tabs! Knowing that Visual studio has a metric ton of settings, I navigate to Tools::Settings::Text Editor::C/C++::Formatting::Indentation, and see the following window:
But changing the highlighted options in any combination actually doesn't affect the indentation at all! None of the other options seem to apply to switch statements, so I don't know what to do. How do I make it not indent 5 spaces, without disabling auto formatting?
And I might add, it not only places 5 tabs when I press enter at the end of the curly brace, but when any auto format event takes place. So when I add a semicolon at the end of a line it places 5 tabs even if I had taken them out before.
This is probably a bit late for you now, but in case someone else finds this issue: it seems to be a Visual Studio bug, you're probably running the freshly installed version of the VS2K13 called REL.
Downloading the Update 4 at http://www.microsoft.com/en-us/download/details.aspx?id=44921 helped in my case.
The curly braces ({ and }) are throwing off the auto-indenter, and it's indenting to one tab beyond the brace.
Braces there are not illegal in a switch statement, but they usually don't do you any good. Unless you need it for scoping a variable declaration, just remove the curly braces. You'll get the same code flow, and you won't confuse the auto-indenter.
EDIT
Come to think of it, you can solve this by simply moving the brace to a new line. This isn't necessarily horrible - it highlights that you're using a brace.
case SDLK_g:
{
// etc
break;
}
I went into VS2013 and created a new project and just tried making a really simple switch but it formatted correctly for me, even with the curly braces. Are you able to post that set of code?
The only other thing I can think of is maybe a setting on how braces are set up, but I don't know why that would affect it. (Nor do I think there is really even a setting for that for C++...) Other than that though you could try just not using the braces at all since you are inside a case statement, you don't technically need them.
Other than that something may have happened during installation. So re-installing is an option too.
EDIT:
Also, could just go with it and finish the code and then when finished just highlight the rows and un-indent ([SHIFT]+[TAB]) them back to their correct spot.

Alternative for "capture" which doesn't suppress the output if the code works

I have a question concerning Stata. I'm executing a loop in which there might be an error. Whether the error occurs depends on the data at hand. Unfortunately I do not know exactly how the data, which my code is used for, looks like. I only know the variables which are in the data. So I use the command capture to let my do-file run even if an error occurs. But if I use this command, Stata also suppresses the output if the command sometimes works in my loop. Of course, that is not what I want.
My command looks like:
capture list year JCage`x' numberfirmsage`x' AvSizeAge`x'
and is part of a loop. So what can I do in order to solve the problem?
The help for capture tells you that this is done by capture noisily.