BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
4 REPLIES 4
LinusH
Tourmaline | Level 20
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
deleted_user
Not applicable
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
LinusH
Tourmaline | Level 20
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
deleted_user
Not applicable
Thanks again, I appreciate your help

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1056 views
  • 0 likes
  • 2 in conversation