DATA M.PROV;
SET M.ORIG_0002;
BY 'PROVIDER ID'n;
IF FIRST.'PROVIDER ID'n THEN OUTPUT M.PROV;
RUN;
When I run this code the im getting
NOTE: Variable 'FIRST.''PROVIDER ID''n'n is uninitialized.
How can I fix could you please help
Put first. in quotes as well:
'first.provider id'n
SAS Documentation - Example: Specify the FIRST. and LAST. BY Variables as Name Literals
Related
I have a problem with numeric and character values.
I did proc contents, so I have variable Poids as characters.
I want to use the following, but it does not change to numeric . best32. is used as it is demanded in problem. Do I do any mistake?
data X;
set Y;
Poids=input(Poids,best32.);
run;
Okay, I found the problem. I cannot have same variable defined as both character and numeric. To fix this problem, I have to rename initial variable in dataset options as shown below and then drop the renamed variable.
data X( drop =Poids_char;
set Y(rename=(Poids=Poids_char));
Poids=input(Poids_char,best32.);
run;
I am writing a macro to help create documentation which must use ods escapechar. I need it to preserve whatever options/setting the original program used. However, setting a new escape character in the macro overwrites the original program's escape character. How can I change the escape character only for the duration of my macro?
Is there a table somewhere in SAS which stores the current ods escapechar? My thought is to assign the current value to a macro variable and use that to reassign it once my process is complete.
Use the escape sequence instead
(*ESC*)
Then you don't have to know or reset anything.
Somewhere around 9.3 (?) they added &SYSODSescapeChar:
%put &=SYSODSescapeChar ;
SYSODSESCAPECHAR=^
But since the generic (*ESC*) mentioned by data_null_ came first, I'm in the habit of using that, rather than do the save option / reset option / restore saved option dance.
I am trying to reformat my variables in SAS using the put statement and a user defined format. However, I can't seem to get it to work. I want to make the value "S0001-001" convert to "S0001-002". However, when I use this code:
put("S0001-001",$format.)
it returns "S0001-001". I double-checked my format and it is mapped correctly. I import it from Excel, convert it to a SAS table, and convert the SAS table to a SAS format.
Am I misunderstanding what the put statement is supposed to be doing?
Thanks for the help.
Assuming that you tried something like this it should work as you intended.
proc format ;
value $format 'S0001-001' = 'S0001-002' ;
run;
data want ;
old= 'S0001-001';
new=put(old,$format.);
put (old new) (=:$quote.);
run;
Make sure that you do not have leading spaces or other invisible characters in either the variable value or the START value of your format. Similarly make sure that your hyphens are actual hyphens and not em-dash characters.
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.