Is this posible?
data have;
input id exc_1 exc_2 exc_3 inc_1 inc_2 inc_3;
cards;
1 1 0 0 0 0 1
2 1 1 0 1 0 0
3 0 0 0 1 1 1
4 0 1 1 0 1 1
;
run;
ID | exclusion_failed | inclusion_failed |
1 | exc_1 | inc_3 |
2 | exc_1, exc_2 | inc_1 |
3 | inc_1, inc_2, inc_3 | |
4 | exc_2, exc_3 | inc_2, inc_3 |
data want;
set have;
length exclusion_failed $200.;
array _excl(*) exc_1-exc_3;
do i=1 to 3;
if _excl(i)=1 then exclusion_failed = catx(", ", trim(exclusion_failed), vname(_excl(i)));
end;
run;
Use VNAME() and basic array logic.
Here's a tutorial on using Arrays in SAS
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/
@Nrjn7 wrote:
Is this posible?
data have;
input id exc_1 exc_2 exc_3 inc_1 inc_2 inc_3;
cards;
1 1 0 0 0 0 1
2 1 1 0 1 0 0
3 0 0 0 1 1 1
4 0 1 1 0 1 1
;
run;
ID exclusion_failed inclusion_failed 1 exc_1 inc_3 2 exc_1, exc_2 inc_1 3 inc_1, inc_2, inc_3 4 exc_2, exc_3 inc_2, inc_3
Rules for what goes where and why.
What can you do with that (ugly) data that the first data set won't let you do?
data want;
set have;
length exclusion_failed $200.;
array _excl(*) exc_1-exc_3;
do i=1 to 3;
if _excl(i)=1 then exclusion_failed = catx(", ", trim(exclusion_failed), vname(_excl(i)));
end;
run;
Use VNAME() and basic array logic.
Here's a tutorial on using Arrays in SAS
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/
@Nrjn7 wrote:
Is this posible?
data have;
input id exc_1 exc_2 exc_3 inc_1 inc_2 inc_3;
cards;
1 1 0 0 0 0 1
2 1 1 0 1 0 0
3 0 0 0 1 1 1
4 0 1 1 0 1 1
;
run;
ID exclusion_failed inclusion_failed 1 exc_1 inc_3 2 exc_1, exc_2 inc_1 3 inc_1, inc_2, inc_3 4 exc_2, exc_3 inc_2, inc_3
Thanks for the help. This was more for the visual of the data. Appreciate and surely will look into array.
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.