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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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