It is hoped to using array to output three different datasets by specfic ID and Type.
Here is the code I wrote. It seems I can only get a subset, not two subsets. Could I get some hints? Many thanks!
DATA NEW;
SET DATA1;
ARRAY IDD[*] $10 ('69' '70');
ARRAY TYPEE[*] $10 ('Red' 'Other');
DO X = 1 TO DIM(ID);
DO Y = 1 TO DIM(TYPE);
IF ID = IDD[X] AND TYPE = TYPEE[Y] THEN OUTPUT;
END;
END;
RUN;
ID | Type | Rater | grape_01 | pH_01 | density_01 |
69 | red | Indivdidual | 4.33 | 2.63 | 1.33 |
69 | red | Indivdidual | 4.48 | 2.72 | 1.31 |
69 | red | Indivdidual | 1.06 | 3.14 | 1.9 |
69 | red | Indivdidual | 3.32 | 2.95 | 1.14 |
69 | red | Indivdidual | 1.2 | 4.16 | 1.1 |
69 | red | Indivdidual | 0.82 | 3.56 | 1.02 |
70 | other | Indivdidual | 7.77 | 2.47 | 1.6 |
70 | other | Indivdidual | 6.13 | 2.63 | 1.33 |
70 | other | Indivdidual | 1.83 | 3.39 | 1.12 |
70 | other | Indivdidual | 0.6 | 3 | 1.13 |
70 | other | Indivdidual | 0.93 | 2.64 | 1.16 |
70 | other | Indivdidual | 2.26 | 4.07 | 1.82 |
70 | other | Indivdidual | 1.14 | 3.15 | 1.24 |
71 | red | Indivdidual | 2.58 | 3.24 | 1.2 |
71 | red | Indivdidual | 10.96 | 3.09 | 1.03 |
71 | red | Indivdidual | 0.4 | 4.18 | 1.12 |
71 | red | Indivdidual | 2.72 | 2.64 | 1.24 |
71 | red | Indivdidual | 3.26 | 2.93 | 1.15 |
71 | red | Indivdidual | 1.56 | 3.97 | 1.34 |
71 | red | Indivdidual | 1.04 | 3.25 | 1.74 |
71 | red | Indivdidual | 1.09 | 3.35 | 2.12 |
71 | red | Indivdidual | 1.98 | 2.82 | 1.05 |
71 | red | Indivdidual | 1.56 | 5.19 | 1.98 |
What I tried to do is, using first two variables as a group id, then output three separate sub-datasets. I wanna try a small data first with three combination scenarios, then apply to large data files with about 20 combinations. Am struggling about which approach would be appropriate. So I started with using array. Please advise if any. Many thanks!
Not too sure what you are after, but maybe one of these two may be a starting point.
data HAVE;
input ID $ TYPE $ Rater : $16. grape_01 pH_01 density_01;
cards;
69 red Indivdidual 4.33 2.63 1.33
69 red Indivdidual 4.48 2.72 1.31
69 red Indivdidual 1.06 3.14 1.9
69 red Indivdidual 3.32 2.95 1.14
69 red Indivdidual 1.2 4.16 1.1
69 red Indivdidual 0.82 3.56 1.02
70 other Indivdidual 7.77 2.47 1.6
70 other Indivdidual 6.13 2.63 1.33
70 other Indivdidual 1.83 3.39 1.12
70 other Indivdidual 0.6 3 1.13
70 other Indivdidual 0.93 2.64 1.16
70 other Indivdidual 2.26 4.07 1.82
70 other Indivdidual 1.14 3.15 1.24
71 red Indivdidual 2.58 3.24 1.2
71 red Indivdidual 10.96 3.09 1.03
71 red Indivdidual 0.4 4.18 1.12
71 red Indivdidual 2.72 2.64 1.24
71 red Indivdidual 3.26 2.93 1.15
71 red Indivdidual 1.56 3.97 1.34
71 red Indivdidual 1.04 3.25 1.74
71 red Indivdidual 1.09 3.35 2.12
71 red Indivdidual 1.98 2.82 1.05
71 red Indivdidual 1.56 5.19 1.98
run;
data NEW;
set HAVE;
if ID in('69','70') and TYPE in ('red','other') then output;
run;
data NEW1 NEW2 NEW3;
set HAVE;
if ID ='69' then output NEW1;
if ID ='70' then output NEW2;
if ID ='71' then output NEW3;
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.