BookmarkSubscribeRSS Feed
Pabster
Obsidian | Level 7

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):
active.png

and like this (inactive companies):

Inactive.png


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;

 

5 REPLIES 5
tomrvincent
Rhodochrosite | Level 12

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.

Pabster
Obsidian | Level 7

Where i am suppose to use it?

tomrvincent
Rhodochrosite | Level 12
It works in either a data statement or proc sql.
Pabster
Obsidian | Level 7

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

Almost.png
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?

andreas_lds
Jade | Level 19
With 9.4m4 or later the you can use the function rand: z = rand("integer", min, max);

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 5 replies
  • 931 views
  • 1 like
  • 3 in conversation