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

Try this one...

%macro test;

            proc sql;

                  select count(distinct fee) into :fees_group

                  from test;

            quit;

            proc sql;

                  create table test as

                  select calendar_day,order_status,fee,sum(no) as total

                  from total

                  group by 1,2,3;

            quit;

        

            %if %eval(&fees_group. EQ 0) %then %do;

                   proc sql;

                          insert into test

                          set calendar_day = 1/8/2013,

                                order_status = "start",

                                fee = "Free",

                                total = .;

                    quit;

             %end;

%mend test;

%test;

DBailey
Lapis Lazuli | Level 10

If you create two static data sets that have all of the values you want:

data work.statuses;

order_status='Start';

output;

order_status='End';

output;

run;

data work.fees;

fee='paid';

output;

fee='free';

output;

run;

Then you can use proc sql to get all of the possible combinations:

proc sql;

select

    m.calendar_day

    ,m.order_status

    ,m.fee

    ,sum(coalesce(h.no,0))as  Total_No

from (

    select distinct    t1.calendar_day, t2.order_status,t3.fee

    from work.have t1, work.statuses t2, work.fees t3) m

    left outer join work.have h

        on m.calendar_day=h.calendar_day

           and m.order_status=h.order_status

           and m.fee=h.fee

group by

    m.calendar_day

    ,m.order_status

    ,m.fee;

quit;

produces

08JAN2013Endfree0
08JAN2013Endpaid0
08JAN2013Startfree4
08JAN2013Startpaid41

Reeza
Super User

If you're not stuck on the format you could do something like the following:

proc sql;

create table want as

Select calendar_day, order_status, fee, sum((fee='paid')*no) as total_paid, sum((fee='free')*no) as total_free

from have

group by calendar_day, order_status;

quit;

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

so the  previous code you sent with the sparse  function works  perfectly Reeza,nice short and  easy.No need to insert any additional records  since the "free" appeares at least once within the week i am supposed to analyze .

So thanks again

Thanks to you all guys for your fancy codes as well Smiley Happy

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
  • 18 replies
  • 1611 views
  • 14 likes
  • 5 in conversation