Hello,
I will try it as simply as possible at first...
I have this dataset:
group n_animals age_difference
1 8 1
2 45 2
4 19 1
And I would like to programme this: if group=1 and n_animals<30 then create variable g2 as group+1 “but only when the next group (group=1+1) has age difference < 2”.
The part in quotes is something I cannot figure out. I would really appreciate if the syntax stayed this way so I do not have to start from scratch.
Look up the POINT= option on the SET statement. You can have one SET statement (with the POINT= option) that reads ahead and one ordinary SET statement that reads the current row to process. There are other ways too. Be sure to not use POINT= to try to read beyond the data.
Look up the POINT= option on the SET statement. You can have one SET statement (with the POINT= option) that reads ahead and one ordinary SET statement that reads the current row to process. There are other ways too. Be sure to not use POINT= to try to read beyond the data.
Assuming I understand your question.
data have; input group n_animals age_difference; cards; 1 8 1 2 45 2 4 19 1 ; data want; merge have have(keep=age_difference rename=(age_difference=_age_difference) firstobs=2); if group=1 and n_animals<30 and _age_difference< 2 then g2=group+1; drop _age_difference; run;
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!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: