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;
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.
I want to modify this code based on start and end dates and val should be incremented by 2,4,6 every 2 days . if for ext="pine" it should have first value as 2 and calculated what the next value will be based for the test data. First record for ext=pine val is 2 and the duration is 8 days 12-may-2018 to 19-may-2018=8
next record 20-may to 29 may then val for same id will be incremented from first record based on dates.
Any help?
Please show a table demonstrating the values of EXD. It is not clear whether your day-count is within EXT class, or accros EXT classes. An output table would help answer such questions.
@vraj1 wrote:
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;
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.
I want to modify this code based on start and end dates and val should be incremented by 2,4,6 every 2 days . if for ext="pine" it should have first value as 2 and calculated what the next value will be based for the test data. First record for ext=pine val is 2 and the duration is 8 days 12-may-2018 to 19-may-2018=8
next record 20-may to 29 may then val for same id will be incremented from first record based on dates.
Any help?
I am not at all sure what you mean by "first 2 days", or "next 2 days". How do you mean values of your "day" variable? Are you "day" variable values continuous? duplicated? are you sure there "next 2 days" or next 4 or what not?
Some example input data and the expected results for that input would clear things up.
First id needs to have exd as 2 and the next as 4 and the rest 6 for
ext='pine'
for
ext='ozi'
it should have first id it should 5 then second record 10 and the rest as 15.
ext='ozi'
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.