BookmarkSubscribeRSS Feed
mehong19
Obsidian | Level 7

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;

 

IDTypeRatergrape_01pH_01density_01
69redIndivdidual4.332.631.33
69redIndivdidual4.482.721.31
69redIndivdidual1.063.141.9
69redIndivdidual3.322.951.14
69redIndivdidual1.24.161.1
69redIndivdidual0.823.561.02
70otherIndivdidual7.772.471.6
70otherIndivdidual6.132.631.33
70otherIndivdidual1.833.391.12
70otherIndivdidual0.631.13
70otherIndivdidual0.932.641.16
70otherIndivdidual2.264.071.82
70otherIndivdidual1.143.151.24
71redIndivdidual2.583.241.2
71redIndivdidual10.963.091.03
71redIndivdidual0.44.181.12
71redIndivdidual2.722.641.24
71redIndivdidual3.262.931.15
71redIndivdidual1.563.971.34
71redIndivdidual1.043.251.74
71redIndivdidual1.093.352.12
71redIndivdidual1.982.821.05
71redIndivdidual1.565.191.98
4 REPLIES 4
Reeza
Super User
Your DIM functions are incorrect - your missing a letter in each one.

Your code also doesn't have anything indicating multiple output datasets.

Is the data above what you have? What do you expect your output to be.
Reeza
Super User
Also, this isn't a recommended practice. What are you trying to accomplish.
mehong19
Obsidian | Level 7

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!

ChrisNZ
Tourmaline | Level 20

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 965 views
  • 0 likes
  • 3 in conversation