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

Dear all,

I ran the following program (propensity score matching):

proc sort data=test out=full ;

by descending tem; run;

proc probit data=FULL noprint;

   class TEM;

   model TEM = FREQ SHARES NUMEST BONUS_PERCENT1 BLACK_OPTION1 ROA1 LG_ASSET MB

IND01-IND10 YeaR03 - YeaR09 / lackfit;

   output out=regdata_out xbeta=gammaw p=pred;

    run;

data GD1 GD0; set regdata_out;

if TEM = 1 then output GD1;

if TEM = 0 then output GD0;

run;

proc sql;

create table temp as select a.tic as TEM1_tic, a.fyear as tem1_fyear, b.*, abs(sum(a.pred, -b.pred)) as diffPS,

min(calculated diffPS) as closest_PS

from GD1 a , GD0 b

group by a.tic, a.fyear

having diffPS = closest_PS;

quit;

proc sql;

create table temp_tem1 as select a.*

from GD1 a, temp b

where

a.tic = b.TEM1_tic and a.fyear = b.tem1_fyear;

quit;

data matchpair; set temp_tem1 temp(drop = tem1_tic); run;

But I could not get the output as it consumes a lot of processing time and a large storage. I am not sure whether there is a more efficient way to obtain the same output as the program above?

Thank you.

Regards,

mspak

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Well. After through the logistic Model  , I found a lot of missing value of pred in both GD0 and GD1 , maybe you do not need it any more , exclude them , it will be very fast.

proc sql;

create table temp as 
select a.tic as TEM1_tic, a.fyear as tem1_fyear, b.*, abs(a.pred - b.pred) as diffPS

from GD1(where=(pred is not missing)) a , GD0(where=(pred is not missing)) b
group by a.tic, a.fyear
having calculated diffPS = min(calculated diffPS);
quit;

Ksharp

View solution in original post

7 REPLIES 7
Ksharp
Super User

You are using Cartesian Product of SQL . therefore, you almost can't get the result when you have a not big table.

What is your sample data?

mspak
Quartz | Level 8

Sorry for late reply. I was experiencing the problem to upload my SAS file. I have updated my query.

Thanks for suggestions.

Mspak

TomKari
Onyx | Level 15

In your first join, you're not specifying any join keys. Because of this, every record in GD1 will be matched with every record in GD0 to create your result, which is probably not what you want.

There are different synaxes for doing this, I recommend the form of:

proc sql;

create table temp as select ...

from GD1 a inner join GD0 b

on a.join_key = b.join_key

...

where join_key represents the fields in GD1 and GD0 that can be used to match the tables.

On the other hand, if you genuinely do need to do a cartesian join, if you provide more details of your objectives I'm sure the group will be able to help improve the speed.

Tom

P.S. If you drop the following string into Google, the first result should take you right to the relevante section of the documentation:

Cartesian Product of LEFTTAB and RIGHTTAB Tables site:support.sas.com

T

Message was edited by: Tom Kari

mspak
Quartz | Level 8

Dear Tom Kari,

Thanks for your suggestion.

I am not going to join with a joining key. I would like to match GD1 and GD0 with the closest_PS. I wish to pair GD1 and GD0 with their closest score (ie. closest_PS).

Regards,

MSPAK

Ksharp
Super User

Well. After through the logistic Model  , I found a lot of missing value of pred in both GD0 and GD1 , maybe you do not need it any more , exclude them , it will be very fast.

proc sql;

create table temp as 
select a.tic as TEM1_tic, a.fyear as tem1_fyear, b.*, abs(a.pred - b.pred) as diffPS

from GD1(where=(pred is not missing)) a , GD0(where=(pred is not missing)) b
group by a.tic, a.fyear
having calculated diffPS = min(calculated diffPS);
quit;

Ksharp

Doc_Duke
Rhodochrosite | Level 12

Lots of missing data in pred is a red flag for me.  That means that those observations are not going to be used in the propensity score matching process (as made explicit in KSharp's code).  You may wish to look at the patterns of missing in the predictors to see if you can refine the initial model.

Doc Muhlbaier

Duke

Message was edited by: Lawrence Muhlbaier See this note for lots on how to do the matching more efficiently http://support.sas.com/kb/30/971.html

mspak
Quartz | Level 8

Thanks you for your suggestion.

It does work.

Regards,

mspak

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 1103 views
  • 0 likes
  • 4 in conversation