BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

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)

7 REPLIES 7
Reeza
Super User

So what's the question?

SASPhile
Quartz | Level 8

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

Reeza
Super User

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

SASPhile
Quartz | Level 8

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?

Reeza
Super User

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.

SASPhile
Quartz | Level 8

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;

Reeza
Super User

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1571 views
  • 0 likes
  • 2 in conversation