DATA Step, Macro, Functions and more

switch

Reply
Super Contributor
Posts: 673

switch

id _jan_xpn   _feb_xpn      _mar_xpn    _apr_xpn           _jan_TUNA     _feb_TUNA    _mar_TUNA     _apr_TUNA     
1       600            .                .                         .                  750                      550                    .                         .    
2             .           .                600                  720                575                     660                     .                        .
3              .           .                    .                 700                      .                     660                650                         .                             


id 1 is sweitch to TUNA
id 2 is switch  from tuna

ideally xpn will take importance over TUNA.

if the score is missing in earlier months in xpn and then score is present in later months in TUNA for that ID,it is called "New to TUNA". (ID 3)

if scores are  present in earlier months in xpn and also scores present in TUNA in later months then "switch to TUNA" (Id 1)

if scores are missing in earlier months and present in TUNA and for subsequent months the scores are present in xpn and not present in TUNA then "Switch from TUNA" (id 2)

Super User
Posts: 19,817

Re: switch

So what's the question?

Super Contributor
Posts: 673

Re: switch

I'm not able to move ahead with these scenarios.how can this be achived with a dataset of 32 MM

Super User
Posts: 19,817

Re: switch

I'm going to assume your question is how to determine the direction of switch from/to Tuna.

1. Set up two arrays one for XPN and one for TUNA

2. Find the starting index of each array that is not missing - I recommend a do - while loop so you don't have to loop through the full array.

3. Compare indexes to determine direction of switch

Super Contributor
Posts: 673

Re: switch

xpn (*) _jan_xpn _feb_xpn _mar_xpn _apr_xpn;


array tuna (*) _jan_TUNA _feb_TUNA _mar_TUNA _apr_TUNA;

well...why to find the starting index that is not missing?

Super User
Posts: 19,817

Re: switch

ID Start_XPN Start_Tuna

1 1 1

2 3 1

3 4 2

ID 2/3 are the same, switch to XPN later in the process.

ID 1 which has the same index is a different scenario that can then be coded for.

Super Contributor
Posts: 673

Re: switch

This is not giving me the expected results:

xpn (*) _jan_xpn _feb_xpn _mar_xpn _apr_xpn;


array tuna (*) _jan_TUNA _feb_TUNA _mar_TUNA _apr_TUNA;


do i=1 to dim(xpn) while (xpn(i) ne .);


if tuna(i)=. then flag='New Account';


else  if tuna(i) > xpn(i) then flag='Switch to Tuna';


else if tuna(i) < xpn(i) then flag='Switch from  Tuna';


end;

Super User
Posts: 19,817

Re: switch

Can you explain your method, I can't follow it?

It doesn't appear to follow the one I suggested, for example where are the indexes calculated.

I'd also suggest trying it without the while condition until you have it working then add it in afterwards.

Ask a Question
Discussion stats
  • 7 replies
  • 344 views
  • 0 likes
  • 2 in conversation