Hello,
My grad student wrote a SAS program where he kept a small number of variables from a larger dataset and in the same program created some new variables from the ones he kept.
He noticed that the log reported operations performed on missing data when he knew he had none. To our dismay, we discovered that the newly created variables and renamed variables were moved to the next line of data so that the new variables were now paired with a different id.
When I ran the keep statement in a separate program from the steps that created the new variables, this did not happen (see both programs, log, and output in attached document).
What went wrong? The potential for this type of error to wreak havoc on a dataset worries me, so I am very anxious to understand it.
Version is SAS 9.4
Many thanks to anyone who can provide insights.
A
Lines 338-341: Calculated values are missing because the data is read AFTER the calculations are done. Move the set statement before math operations.
Many thanks for the quick reply. A simple error that has great potential for creating problems.
Indeed! Most errors are reflected in one way or another in the log. Don't hesitate to consult again if you see anything suspicious.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.