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

Hi Guys!

 

I'm in a little pickle here. Let me explain....

 

The overall project is to take information from the variable columns and give then a weight then score. However, there are so many variables to weigh and score that it would be really tedious to do each one individually. I am looking for a macro paired with do loops to process this data in short, efficient code. For example:

 

proc sort data=have
 out=want;
 by id year descending doc_num;
 run;

 

data _null_;
 set have(where=(year=&curryr. or year=&prevyr. and doc_num=&.));

by id;
 if name then a_weight = 'L' and a_score='L';
 if first.sale_dt = . and last.sale_dt = . then weight='M' and score='M';
  else if first.sale_dt is not . and last.sale_dt = . then weight='M' and score='L';
  else if first.sale_dt = . and last.sale_dt is not . then weight = 'M' and score='L';
  else if first.sale_dt ^= last.sale_dt then weight='M' and score='M';
  else if first.sale_dt = last.sale_dt then weight='M' and score='L';

run;

 

The other variables and weights will be different than above, but the expressions will stay the same.....

For instance: if price is missing on both days then weight ='L' and score='L' and so on.....

                        OR

                      if product is missing on both days then weight='M' and score='L' and so on....

 

The final objective is to put the weight and score through a calculation (adding up all of the scores with a corresponding number) to get the total document score.
  
 Suggestions?

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@DrBigAl wrote:
I am comparing records from this year and last year. I would only want the records for 2017 and 2018. So or is correct.

I couldn't test the code because I only have table names. Data hasn't been loaded as of yet. I really just need to map things out with a plan until the data is loaded

Instead of the "AND" which will not select any records look at

 

year in (&curryr.  &prevyr.)

which is an OR condition.

Please examine the results of this code and see which one you want. This will be have exactly the same as your "where" logic for the year variable.

data example;
   curryr = 2017;
   prevyr = 2018;
   year = 2017;
   if year=2017 and year=2018 then value= 'Yes Match';
   else value= 'No Match';
   if year in (2017 2018) then oth = 'Yes Match';
   else oth = 'No Match';

run;

View solution in original post

5 REPLIES 5
Astounding
PROC Star

A macro can generate all the code you might need, but you can't do that yet.  First, you must have working code for one individual case.  Then you can contemplate using a macro to expand that to many cases ... if a macro is needed.  But the program that you posted is not working code. So get it working first, then we can talk about the next step.

ballardw
Super User

You do realize that this snippet of code

 set have(where=(year=&curryr. and year=&prevyr.

is only going to have any output records when &curryr = &prevyr don't you? In which case why are there two comparisons?

 

Or do you want records when the value of the year variable is either &curryr. or &prevyr?

DrBigAl
Fluorite | Level 6
I am comparing records from this year and last year. I would only want the records for 2017 and 2018. So or is correct.

I couldn't test the code because I only have table names. Data hasn't been loaded as of yet. I really just need to map things out with a plan until the data is loaded
ballardw
Super User

@DrBigAl wrote:
I am comparing records from this year and last year. I would only want the records for 2017 and 2018. So or is correct.

I couldn't test the code because I only have table names. Data hasn't been loaded as of yet. I really just need to map things out with a plan until the data is loaded

Instead of the "AND" which will not select any records look at

 

year in (&curryr.  &prevyr.)

which is an OR condition.

Please examine the results of this code and see which one you want. This will be have exactly the same as your "where" logic for the year variable.

data example;
   curryr = 2017;
   prevyr = 2018;
   year = 2017;
   if year=2017 and year=2018 then value= 'Yes Match';
   else value= 'No Match';
   if year in (2017 2018) then oth = 'Yes Match';
   else oth = 'No Match';

run;
DrBigAl
Fluorite | Level 6

Thank you! This helped me refocus my efforts.

 


  

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 1026 views
  • 1 like
  • 3 in conversation