BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
HarfordKaren
Calcite | Level 5

I have attempted the following code and it is not working. I'm not sure how to get the graduation information in the mix to help decide if the student is retained in the major (r_info_#) from one year to the next.  If the student graduates (g_info_#) then they need to be deleted from the retention file. There are 5 g_info_# files with the data being gmaj1_1 gmaj2_1 gmaj3_1.... gmaj1_2....gmaj1_3.... etc.  Can someone tell me the best way to inclde the g_info files into the processing with the r_info files so I can delete out the records when the student graduates rather then showing they were not retained. Thanks!

 

data rinfo;
merge prdata.r_info_1 prdata.r_info_2 prdata.r_info_3 prdata.r_info_4
prdata.r_info_5 prdata.r_info_6;
by pidm_key;
array m {6} $ majr1-majr6;
array d {6} $ deg1-deg6;
array r {5} ret1-ret5;

do i=1 to 5;

set prdata.g_info_&i.(keep=rename(gmaj1_&i.=gmaj1 gmaj2_&i.=gmaj2
gmaj3_&i.=gmaj3 gmaj4_&i.=gmaj4 gmaj5_&i.=gmaj5) key=pidm_key;
if _iorc_ ne 0 then do;
_error_ = 0;
found=0;
end;
else found=1;

if m{i}^= ' ' then do;
if m{i+1}=m{i} and d{i+1}=d{i} then r{i}=1;
else if found =1 then do;
if gmaj1 = m(i+1) or
gmaj2 = m(i+1) or
gmaj3 = m(i+1) or
gmaj4 = m(i+1) or
gmaj5 = m(i+1) then delete;
else r{i}=0;
end;
else r{i}=0;
end;
end;
ret6=0;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Difficult to answer your question without knowing more about the data. Since you're using MERGE to combine the files, remember that merge can't handle many to many merges. Does the student ID only appear at most once in each file?

 

As for how to delete graduates, I would combine the five graduate files into one file (i.e., merge by the student id), and then include it in the merge with the other files but using something like GRADS(IN=inG).

 

Then, as part of the merge, include the statement: if not inG;

 

HTH,

Art, CEO, AnalystFinder.com

 

View solution in original post

5 REPLIES 5
art297
Opal | Level 21

Difficult to answer your question without knowing more about the data. Since you're using MERGE to combine the files, remember that merge can't handle many to many merges. Does the student ID only appear at most once in each file?

 

As for how to delete graduates, I would combine the five graduate files into one file (i.e., merge by the student id), and then include it in the merge with the other files but using something like GRADS(IN=inG).

 

Then, as part of the merge, include the statement: if not inG;

 

HTH,

Art, CEO, AnalystFinder.com

 

HarfordKaren
Calcite | Level 5
The student id appears once in each file. The hard part is that I don't want to take the student out of the retention until after they have graduated. This is a report that looks at retention in a major over a 5 year period.
HarfordKaren
Calcite | Level 5

I was able to figure it out and rework the table. Thank you.

Kurt_Bremser
Super User

Please supply example data (in data steps with datalines), and the expected result.

At the moment your code is so full of syntax and other errors that I can't make any sense of it. Besides the horrible formatting.

HarfordKaren
Calcite | Level 5

It was coding that I inherited. I was able to figure it out and get the table reworked.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1211 views
  • 0 likes
  • 3 in conversation