Keep statement and creation of variables in same program leads to misread data--what went wrong?

Reply
Occasional Contributor
Posts: 7

Keep statement and creation of variables in same program leads to misread data--what went wrong?

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

 

 

 

Respected Advisor
Posts: 4,919

Re: Keep statement and creation of variables in same program leads to misread data--what went wrong?

Lines 338-341: Calculated values are missing because the data is read AFTER the calculations are done. Move the set statement before math operations.

PG
Occasional Contributor
Posts: 7

Re: Keep statement and creation of variables in same program leads to misread data--what went wrong?

Many thanks for the quick reply.  A simple error that has great potential for creating problems. 

 

 

Respected Advisor
Posts: 4,919

Re: Keep statement and creation of variables in same program leads to misread data--what went wrong?

Indeed! Most errors are reflected in one way or another in the log. Don't hesitate to consult again if you see anything suspicious.

PG
Ask a Question
Discussion stats
  • 3 replies
  • 363 views
  • 2 likes
  • 2 in conversation