BookmarkSubscribeRSS Feed
animesh123
Obsidian | Level 7

DATA output;

set input;

if mCX_Tier=1 then default_plan=ceil(4/tgt_cnt);
else if mCX_Tier=2 then default_plan=ceil(3/tgt_cnt);
else if mCX_Tier=3 then default_plan=ceil(1/tgt_cnt);
else IF mCX_Tier=4 THEN default_plan=0;


if pSG_Tier=1 then default_plan=plan(3/tgt_cnt);
else if pSG_Tier=2 then default_plan=ceil(2/tgt_cnt);
else if pSG_Tier=3 then default_plan=ceil(1/tgt_cnt);
else IF pSG_Tier=4 THEN default_plan=0;

run;
here tgt_cnt is 1

So this code is not working for me As tier is getting overlapped e.g- mCX_Tier=1 is getting overlapped with pSG_Tier=3
What I am trying to do is then there is two column p1 and p2 and also we required minimum tier other than below conditon

MCX FALLS IN 1/2 then P1 should have MCX and PSG should get into P2
and
PSG falls in 3 and MCX FALLS in 4 THEN P1 will get TSG and P2 get SCX

9 REPLIES 9
andreas_lds
Jade | Level 19

Read your post multiple times, but still it is not clear what you expect as result. Please post some data and the expected results.

animesh123
Obsidian | Level 7

the data look like this and the ouput data too

Screenshot 2022-11-11 202659.png

animesh123
Obsidian | Level 7
So the code which is up there is totally wrong .I am also working on creating on new code which follows the codition
ballardw
Super User

Please provide example data in the form of data step code. It is extremely hard to write code against pictures. Do not mix "input" with output data as we still don't know where you are starting from.

animesh123
Obsidian | Level 7

So the Input step will look like this and the o/p data is above

 

Screenshot 2022-11-12 103324.png

animesh123
Obsidian | Level 7

DATA output;

set input;

if mCX_Tier=1 then default_plan=ceil(4/tgt_cnt);
else if mCX_Tier=2 then default_plan=ceil(3/tgt_cnt);
else if mCX_Tier=3 then default_plan=ceil(1/tgt_cnt);
else IF mCX_Tier=4 THEN default_plan=0;


if pSG_Tier=1 then default_plan=plan(3/tgt_cnt);
else if pSG_Tier=2 then default_plan=ceil(2/tgt_cnt);
else if pSG_Tier=3 then default_plan=ceil(1/tgt_cnt);
else IF pSG_Tier=4 THEN default_plan=0;

run;
here tgt_cnt is 1

So this code is not working for me As tier is getting overlapped e.g- mCX_Tier=1 is getting overlapped with pSG_Tier=3
What I am trying to do is then there is two column p1 and p2 and also we required minimum tier other than below conditon

MCX FALLS IN 1/2 then P1 should have MCX and PSG should get into P2
and
PSG falls in 3 and MCX FALLS in 4 THEN P1 will get TSG and P2 get SCX

ChrisHemedinger
Community Manager

I can't say I really understand the rules here, but clearly the outcome depends on the combo of two factors and the second IF-THEN block can undo the logic of the first IF-THEN block. 

 

I'd try to rearrange to evaluate the two items together and apply the precedence rules. So a single IF-THEN-ELSE block that evaluates the conditions together, or alternatively SELECT WHEN (may be easier to read in this case, but functionally the same).

 

DATA output(drop=factor);
	set input;
	length factor 8;
	factor = 0;
	
    /* only first WHEN condition that is true will apply */
    select;
     when (mCX_Tier=1) factor=4;
     when (mCX_Tier=2 or pSG_Tier=1) factor=3;
     when (mCX_Tier=3 or pSG_Tier=3) factor=1;
     when (mCX_Tier=4 or pSG_Tier=4) factor=0;     
    end;
   
	/* assuming tgt_cnt is never 0 */
	default_plan = ceil(factor/tgt_cnt);

run;

(Also not sure why you need the ceil function, but maybe you have cases where the numbers aren't integers.)

SAS Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.
andreas_lds
Jade | Level 19

@animesh123 Please don't repeat questions, this causes confusion only.

andreas_lds
Jade | Level 19

Impossible to understand what you have and what you want. Please post data in usable form: a data step using datalines.

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!
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.

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
  • 9 replies
  • 878 views
  • 0 likes
  • 4 in conversation