I have the following statement within my proc print:
where ZBTESTCD = 'NEOPSTYP' and missing(input(zbdtc,??e8601dt.));
And the SAS issues an error when I run it:
ERROR: Syntax error while parsing WHERE clause.
ERROR 22-322: Expecting a format name.
ERROR 200-322: The symbol is not recognized and will be ignored.
This very same condition missing(input(zbdtc,??e8601dt.)) works fine when used within if in a datastep.
Is this documented behavior? Any better workaround than having a datastep preceding proc call?
The double ?? is used to suppress the setting of _ERROR_ in a data step. So it would have no meaning in a WHERE clause, especially one used in a PROC instead of a DATA step.
Just use a single ?.
? or ??
specifies the optional question mark (?) and double question
mark (??) modifiers that suppress the printing of both the error
messages and the input lines when invalid data values are read. The ?
modifier suppresses the invalid data message. The ?? modifier also
suppresses the invalid data message and, in addition, prevents the
automatic variable _ERROR_ from being set to 1 when invalid data are
read.
Related
I am working with data in SAS environment. I'm trying to replace missing values with blanks for an entire table. Missing values can be found in columns that are both character and numeric.
I tried using the following:
RSUBMIT; proc stdize data=Final_note out=final_note_blanks reponly missing=''; run; quit; ENDRSUBMIT;
but since some of the columns are operating on numeric data types, this won't work because '' is a character. Below is the error message I received:
Syntax error, expecting one of the following: a numeric constant, a datetime constant, ABW, AGK, AHUBER, AWAVE, EUCLEN, IQR, LEAST, MAD, MAXABS, MEAN, MEDIAN, MIDRANGE, RANGE, SPACING, STD, SUM, USTD. The symbol is not recognized and will be ignored
You cannot replace a missing numeric value with a blank. This can only be done with character values. However, you can represent missing values as blank for reporting purposes.
options missing = '';
This only changes the way it is presented. SAS still sees it as a missing numeric value.
I am trying to write a macro that creates a text file using parameter value. I understand all SAS parameters are passed as text, so i need to convert the text to numeric. Using INPUT for this but still getting a syntax error. Appreciate the help. Thank you.
code:
%macro test(n_var);
data _null_;
file"c:/temp/test.txt" TERMSTR=crlf;
put ;
put "(numeric variable passed = "input(&n_var,8.)")";
put ;
run;
%mend;
%test(n_var=100);
Log:
SYMBOLGEN: Macro variable N_VAR resolves to 100
NOTE: Line generated by the macro variable "N_VAR".
39 100
___
22
76
MPRINT(TEST): put "(numeric variable passed = "input(100,8.)")";
MPRINT(TEST): put ;
MPRINT(TEST): run;
ERROR 22-322: Syntax error, expecting one of the following: a name, arrayname, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.
ERROR 76-322: Syntax error, statement will be ignored.
All SAS macro symbols (aka variables) are text. SAS macro parameters are text.
Your use case probably does not need to convert text to numeric.
Consider:
%let x = 100;
data _null_;
my_num_var = &x;
run;
The resolution of the macro variable (or perhaps better understood as 'symbol') are the letters 1 0 0, but with respect to text to be interpreted as SAS code. The data step compiler infers my_num_var is numeric from the line it sees as
my_num_var = 100;
There are some use cases where you may want to test that a macro parameter can be interpreted as a numeric value. Such use cases are probably beyond your needs at this time.
The INPUT function is one of those special DATA Step functions that is not available for use in SAS macro via the %sysfunc function. When you must 'input' a value in a 'pure' manner outside a DATA step, you will want to invoke the INPUTN or INPUTC functions via %sysfunc
%let evaluatedRepresentation = %sysfunc(inputn(&x,best8.));
The numeric evaluation of the inputn is converted to text and assigned to symbol evaluatedRepresentation.
If you are not in control of the callers to you macros in which you do ampersand evaluations the safer approach is to evaluate via SUPERQ to break code injections and other anamolies
%let evaluatedRepresentation = %sysfunc(inputn(%superq(x),best8.));
I am trying to use the set statement for multiple datasets in one shot namely I have datasets vmoreranked1,vmoreranked2,vmoreranked3,...But constantly getting an error
data stackorig;
set vmoreranked1-vmoreranked&vmcnt; run;
-
22
ERROR 22-322: Syntax error, expecting one of the following: a name, a
quoted string, (, ;, END, KEY,
KEYS, NOBS, OPEN, POINT, DATA, LAST, NULL.
NOTE: The SAS System stopped processing this step because of errors.
Can someone help?
Unless you are running an old version of SAS that does not support using ranges of dataset names then you probably have leading spaces in your macro variable. For example if I run this code:
data _null_;
call symput('vmcnt',' 2');
run;
data stackorig;
set vmoreranked1-vmoreranked&vmcnt;
run;
I get your error message, but I also get another message that explains the problem.
2071 vmoreranked 2
-
22
200
ERROR: Missing numeric suffix on a numbered data set list (WORK.vmoreranked1-WORK.vmoreranked).
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, ;, CUROBS,
END, INDSNAME, KEY, KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.
ERROR 200-322: The symbol is not recognized and will be ignored.
You should fix how you are creating macro variable so that the leading spaces are not included.
Or you can just remove the leading spaces by re-creating it like this:
%let vmcnt=&vmcnt ;
After having worked out a bunch of other errors I'm left with the following
ERROR: P does not have a numeric suffix.
From all the info I've been able to find this happens a lot when using PROC TRANSPOSE, however I'm not using that here (and don't anywhere else in this code).
Data Spillover_HE (rename=(F1=FY F2=BN F3=employeeID F4=grade_subject_ID
F5=AsmtID_agg F6=linkB F7=subgroupID F8=w F9=MGP_SE F10=Residual_SE
F11=Residual_Var F12=mgp_var F13=student_n F14=calcID F15=sumwt F16=MGP
F17=ave_prescore F18=p_imp F19=p_postImp F20=p_sped F21=p_sped_rs
F22=p_sped_se_ss F23=p_sped_st F24=p_sped_tt F25=P-ell F26=p_ed
F27=p_hispanic F28=p_black F29=p_white F30=p_asian F31=p_other
F32=p_blahispmale F33=p_overaundcred F34=p_retained F35=p_transfer
F36=p_top10 F37=p_top5 F38=p_top1 F39=p_bot10 F40=p_bot5 F41=p_bot1
F42=target_population F43=mean_residual_var F44=P_0_5)); run;
Obviously I have a bunch of variables that start with "p". None of them are underlined in the log. I'm using SAS Base, and got the same error in SAS Enterprise Guide.
Not sure what my next move should be. Thanks.
A dash is not a correct character in a variable name.
Replace F25=P-ell into F25=P_ell.
You can use dash to specify a range of variables e.g. rename=(x1-x100=y1-y100). This code renames 100 variables with prefix x to y.
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.