i want to assign values for EXD based on the below condition
EXT is "pine", EXD should be assigned by value 2 for the first 2 days, value 4 for the next 2 days and value 6 for the remaining Period A. If EXT is "ozi", EXD should be assigned by value 5 for the first 2 days, value 10 for the next 2 days and value 15 for the remaining Period A.
Attached test data. can any one suggest how to do it.?
Hi @vraj1,
There are at least two possible interpretations of your criteria and hence different solutions:
data want;
set test(drop=exd);
if period='A' then do;
if ext='pine' then exd=2*min(int((day+1)/2),3);
else if ext='ozi' then exd=5*min(int((day+1)/2),3);
end;
run;
data want;
set test(drop=exd);
by id day;
if first.id then call missing(_cp, _co);
if period='A' then do;
if ext='pine' then do; _cp+1; exd=2*min(int((_cp+1)/2),3); end;
else if ext='ozi' then do; _co+1; exd=5*min(int((_co+1)/2),3); end;
end;
drop _:;
run;
Hi @vraj1,
There are at least two possible interpretations of your criteria and hence different solutions:
data want;
set test(drop=exd);
if period='A' then do;
if ext='pine' then exd=2*min(int((day+1)/2),3);
else if ext='ozi' then exd=5*min(int((day+1)/2),3);
end;
run;
data want;
set test(drop=exd);
by id day;
if first.id then call missing(_cp, _co);
if period='A' then do;
if ext='pine' then do; _cp+1; exd=2*min(int((_cp+1)/2),3); end;
else if ext='ozi' then do; _co+1; exd=5*min(int((_co+1)/2),3); end;
end;
drop _:;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.