I have this syntax to achieve this result:
data have;
set want;
array xs(*) var1-var5
all = max(of xs(*));
run:
var1 var2 var3 var4 var5 all
1 . . . . 1
. 3 . . . 3
. . 2 . . 2
. . . 6 . 6
. . . . 8 8
If I have data like this, where var3 is missing, will the same syntax work for this?
var1 var2 var4 var5 all
1 . . . 1
. 3 . . 3
. . 2 . 2
. 6 . . 6
. . . 8 8
data have;
set want;
all = max(of var: );
run:
data have;
set want;
all = max(of var: );
run:
Or, if your variables names don't start with "var", you could use a variable list that only relies on the variable order in the dataset. i.e.:
data want; set have; array xs(*) var1--var5; all = max(of xs(*)); run;
Art, CEO, AnalystFinder.com
Yes.
But SAS will create an empty (all missing) variable named VAR3.
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.
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.