BookmarkSubscribeRSS Feed
Ksharp
Super User

Hi NiuNiu

Yes.

I admit that Cartesian Product of sql is a little faster than data step.

But data step 's Cartesian Product is more powerful, which can do more than sql.

Especially for some complex situation, I prefer to use data step.

SQL is designed based on Cartesian Product, so maybe it is optimized by some skill.

And data step need to open dataset each time of iteration, so it is maybe the cause to waste more time than sql.

So for some simple problem, I recommend to use sql, But for some complicated problem which sql can not accomplish. The only choice is data step Smiley Sad

Thanks!

Ksharp

Ksharp
Super User

Hi. I recode it by using proc sql.

But not know how fast will it be .

data temp;
input account $ date : mmddyy10. test id;
format date mmddyy10.;
cards;
384000 6/30/2010 1 13.15
384000 6/15/2010 1 13.14     
384000 6/10/2010 1 13.14     
384000 6/1/2010  1 13.13
386000 5/30/2010 1 12.12
386000 5/15/2010 1 12.12
386000 4/25/2010 1 12.13
;
run;
proc sql;
 create table op as
  select a.*,b.date as _date ,b.id as _id ,case
                                              when a.id=b.id then 1
                                              when b.id is missing then 1
                                               else 0
                                            end as count
   from temp as a left join temp as b
    on a.account=b.account and b.date between a.date-30 and a.date-7;

 create table flag as
  select account,date,not(sum(count)) as flag
   from op
    group by account,date;


 create table want as
  select a.*,flag
   from temp as a left join flag as b
    on a.account=b.account and a.date=b.date
    ;
quit;

Ksharp

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 16 replies
  • 1706 views
  • 0 likes
  • 2 in conversation