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
Read your post multiple times, but still it is not clear what you expect as result. Please post some data and the expected results.
the data look like this and the ouput data too
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.
So the Input step will look like this and the o/p data is above
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
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.)
@animesh123 Please don't repeat questions, this causes confusion only.
Impossible to understand what you have and what you want. Please post data in usable form: a data step using datalines.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: