BookmarkSubscribeRSS Feed
kfwright23
Fluorite | Level 6

I attempted to replicate the code listed in the appendix of this paper:

http://support.sas.com/resources/papers/proceedings10/061-2010.pdf 

 

I do not think that this step is working for me.  I would greatly appreciate any suggestions to correct my code.

************Select the first case- the step is repeated for all cases**************;

 data active;

setnumber = 1;

set cases point=setnumber ;

output;

stop;

run;

 

Below is the code that I used with my variables, not using the macro:

/****************** Code Generated From Call of Macro *************
Assume a working data set named cases and controls
************************************************************************/
* Sort control dataset by a random number;
proc sql;
create table random_controls as
SELECT *,
ranuni(12345) as random from controls order by random;
quit;


* Rename control variable names - put c_ at beginning (code not shown);
* Select the first case- the step is repeated for all cases;

data active;
setnumber = 1;
set TalTen point=setnumber;
output;
stop;
run;


********************************************************************
Main section of the program. Create dataset for matches, non-matches
********************************************************************;
data match (keep = bannerid pell act_maxcomp hs_gpa3 setnumber ccstat)
nomatch (keep = bannerid pell act_maxcomp hs_gpa3)
used (keep= c_bannerid);
set active ; * This has the current case;

* Read through control dataset with random access and pointer option;
do i = 1 to totobs;
set random_controls point=i nobs=totobs;

* Check if case and control data match;


if abs (pell - c_pell) = 0 and
abs (act_maxcomp - c_act_maxcomp) <= 1 and
abs (hs_gpa3 - c_hs_gpa3) <= .2 then do;
* We have a match!;
ccstat= 1;
output match; * This is the case data, aadding variable ccstat = 1;


* Store control values in variables with same name as case;
* Then output again to same dataset;
pell = c_pell;
act_maxcomp = c_act_maxcomp;
hs_gpa3 = c_hs_gpa3;
bannerid = c_bannerid;
ccstat= 2;
output match;
* Output control data values to USED dataset;
output used;
stop; * Need to end DATA step since we have a match;
end;
end; * ends I loop;
output nomatch; * If I loop is exhausted then no match;
run;

/*SAS Global Forum 2010 Coders' Corner
9*/

proc append data=match
base=matchall;

proc append data=nomatch
base=nomatchall;

* Need to re-sort control dataset by subject id;
proc sort data=random_controls;
by c_bannerid;

* Remove used control from control dataset;
data random_controls;
merge random_controls
used (in=used);
by c_bannerid;
if used ne 1; *aka ^= ;
run;

* Need to resort control dataset by random number for next iteration;;
proc sort data=random_controls;
by random;

1 REPLY 1

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 ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 2412 views
  • 2 likes
  • 1 in conversation