Hi all.
I posted this question before but apparently it looks more like a case of random case-control sampling.
So my data looks like this(Active companies):
and like this (inactive companies):
I need SAS to randomly select an ACTIVE(so the COSTAT of the company =0) company from the Active data set and pair it to an Inactive company(COSTAT=1) from my second data set.
The pairing only has two constraint:
the active company must be in the same industry as the inactive one (same SIC) and the same Fyear for proper analysis.
Afterwards any Inactive company that has no match should deleted.
My final set should look somehow like this:
DATADATE FYEAR DLRSN CONM DLDTE COSTAT SICH
03/12/1992 1989 . A 0 112
03/12/1993 1989 02 B 1990 1 112
03/12/1994 1990 . D 0 333
03/12/1992 1990 03 F 1992 1 333
03/12/1993 1994 . J 0 445
03/12/1994 1994 03 L 1996 1 445
03/12/1998 1998 . I 0 001
03/12/1998 1998 02 Z 2000 1 001
Hope it`s clear and you guys can me help me out.
*UPDATE*
I used this code to create a random sample data set for the active companies and then merge it with the inactive one. Their is just no pairing what so ever. I just need ONE active for ONE inactive.:
proc surveyselect data=AltmanV2.Donnee_Avant_F_Sante
out=StratifiedSRS
sampsize=1643
method=srs
outall;
strata COSTAT;
run;
data Strat;
set StratifiedSRS;
if Selected=1 then output;
else delete;
run;
data test;
set Strat AltmanV2.Donnee_Avant_F;
SIC=INT(input(SIC,4.)/100);
run;
proc sort data= test;
by Fyear SIC;
run;
use this to pick a random integer:
%macro RandBetween(min, max);
(&min + floor((1+&max-&min)*rand("uniform")))
%mend;
add a record number (_n_) to your dataset and pick a number (%RandBetween(1, 1643 )).
That should help you get your 1 record.
Where i am suppose to use it?
I integrated the code to the Active company data set like this:
data Random;
set SicMatch;
%macro RandBetween(min, max);
(&min + floor((1+&max-&min)*rand("uniform")))
%mend;
Choice=%RandBetween(1,3154);
run;
and then merged it with the Inactive dataset by choosing only numbers between 1 and 1647 ( so one per intactive company).
here is the result
But it still doesn`t quite give me this format:
DATADATE FYEAR DLRSN CONM DLDTE COSTAT SICH
03/12/1992 1989 . A 0 112
03/12/1993 1989 02 B 1990 1 112
03/12/1994 1990 . D 0 333
03/12/1992 1990 03 F 1992 1 333
03/12/1993 1994 . J 0 445
03/12/1994 1994 03 L 1996 1 445
03/12/1998 1998 . I 0 001
03/12/1998 1998 02 Z 2000 1 001
any clue on how I can arrange my data to obtain this format?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.