As you know, Proc Reg gives errors when whole values are missing. I have a character type variable, I want to prevent the error "No valid observations are found". I know it is related to data but I want to prevent it without fix the data.
I tried following Where statement but it sitill gives same error.
PROC REG DATA=sampleData(Where=(charVariable not is missing)) PLOTS(ONLY)=ALL;
By charVariable ;
I take it that you want to exclude those BY groups from the analyses where all observations have at least one missing value in the response or regressor variables (which causes the error message "No valid observations are found.").
You haven't shown your MODEL statement, so let's look at a generic example:
model y=x1 x2;
Let SAS find out which BY groups are to be excluded:
proc sql noprint;
into :_excl separated by ' '
group by charVariable
having min(nmiss(y, x1, x2));
This PROC SQL step creates a list of the quoted values of charVariable to be excluded* and writes this list into macro variable _EXCL -- unless no values need to be excluded, in which case the initial value 'dummyvalue' remains in _EXCL. So, &_EXCL will never resolve to a null string and is valid in a WHERE condition like this:
proc reg data=sampleData(where=(charVariable not in (&_excl)));
Of course it is assumed that 'dummyvalue' is not among the values of charVariable for which you want to perform an analysis.
To adapt the above code to your needs, please replace "y" by the name of your response variable and "x1, x2" by the list of your regressor variable(s).
*For each observation in a BY group it determines the number of missing values among response (y) and regressor variables (x1, x2) and if the minimum of all these numbers within a BY group is not zero (hence >=1, i.e., all observations of the BY group have at least one missing value), the BY value is appended to the list in _EXCL.
PS: Your existing WHERE condition may look odd, but it's syntactically correct.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.