DATA Step, Macro, Functions and more

Macro programming help to look at additional data

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

Macro programming help to look at additional data

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;


Accepted Solutions
Solution
‎02-10-2017 09:29 AM
PROC Star
Posts: 7,364

Re: Macro programming help to look at additional data

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


All Replies
Solution
‎02-10-2017 09:29 AM
PROC Star
Posts: 7,364

Re: Macro programming help to look at additional data

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

 

Occasional Contributor
Posts: 16

Re: Macro programming help to look at additional data

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.
Occasional Contributor
Posts: 16

Re: Macro programming help to look at additional data

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

Super User
Posts: 6,963

Re: Macro programming help to look at additional data

[ Edited ]

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 16

Re: Macro programming help to look at additional data

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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