Help using Base SAS procedures

SAS Code Help

Reply
N/A
Posts: 0

SAS Code Help

I am relatively new to SAS, and was hoping someone could help me.

I have the following variables--Name, Test, and Result in a spreadsheet that looks similar to this:

Name Test Result
John Doe Math Pass
John Doe English
John Doe History

The results for English and History are blank. I need them to say "Pass" as well. If any of John's test results say "Pass", then any test that has a blank result must also say "Pass". The same applies if one of his test results were to say "Fail".

The spreadsheet has a list of different names with many tests and results, and each name is listed several times for each test. The results for each exam should all be made the same for each person.

Can someone please give me an example of the SAS code I need to use to fill on the blanks on the spreadsheet? Thanks so much.

Message was edited by: State2000

Message was edited by: State2000 Message was edited by: State2000
Super User
Posts: 5,432

Re: SAS Code Help

Posted in reply to deleted_user
This code assumes that you have managed to import your spreadsheet to SAS. It also assumes that you don't have mixture of Pass and Fail for the same student. If this is the case, you have to develop the logic a bit in the data step.


proc sort data=exams;
by name descending result ;
run;

data exams2;
set exams;
by name;
retain res;
if first.name then res=result;
else if result = ' ' then result = res;
drop res;
run;

Hope this helps,
Linus
Data never sleeps
N/A
Posts: 0

Re: SAS Code Help

Posted in reply to deleted_user
Thanks so much Linus! This worked and helped me out a great deal. I do have one more question. Some of the Names have blank results for all tests. I need those to say "Fail". Can this program be modified to fill in those blank results as well?

Thanks again
Jimmy
Super User
Posts: 5,432

Re: SAS Code Help

Posted in reply to deleted_user
Well, yes. After the sort, you will know on the first observation per student, because Fail will be sorted before a blank (descending):

data exams2;
set exams;
by name;
retain res;
if first.name then do;
if result eq ' ' then result = 'Fail';

res=result;
end;
else if result = ' ' then result = res;
drop res;
run;

/Linus
Data never sleeps
N/A
Posts: 0

Re: SAS Code Help

Posted in reply to deleted_user
Thanks again, I appreciate your help
Ask a Question
Discussion stats
  • 4 replies
  • 137 views
  • 0 likes
  • 2 in conversation