After running this code, I am seeing all basins, not just NA or na. What am I doing wrong? It just doesn't make sense to me that this would be ignored and there is no error to help me see why.
***********************************************************;
* Activity 3.06 *;
* 1) Modify the OUT= option in the PROC SORT statement *;
* to create a temporary table named STORM_SORT. *;
* 2) Complete the WHERE and BY statements to answer *;
* the following question: Which storm in the North *;
* Atlantic basin (NA or na) had the strongest *;
* MaxWindMPH? *;
***********************************************************;
proc sort data=pg1.storm_summary out=storm_sort;
where Basin = 'NA' or 'na';
by descending MaxWindMPH;
run;
Your syntax is wrong.
where Basin = 'NA' or 'na';
should be
where Basin = 'NA' or basin='na';
From now on, when your code isn't working, show us the LOG so we can see the code along with NOTEs, ERRORs and WARNINGs that appear in the log.
Thank you. I see now that the variable has to be listed again for the boolean operator to apply for a where statement.
Another approach when comparing a single variable to a list of values is to use the IN operator:
Where basin in ('NA' 'na');
which is the same as multiple 'or'.
Another considering the difference between the values listed to make the case consistent:
Where upcase (basin) = 'NA';
Which makes the value compared to the list all upper case. If you actually have other case differences like "nA" or "Na" this might be preferred.
You need to whrite the code this way :
proc sort data=pg1.storm_summary out=storm_sort;
where Basin in("NA" "na");
by descending MaxWindMPH;
run;
or you can just modify the where instructions as: where Basin= 'NA' or Basin= 'na'
Because the non empty string 'na' is considered TRUE by SAS.
So your where condition reduces to WHERE (test1) or TRUE. Which is always going to be TRUE.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.