i have a datset
data test;
input store sales;
cards;
1 .
1 200
1 300
1 .
2 .
2 300
2 150
2 560
3 900
3 560
3 .
;
run;
i want the first non missing value of each store?
data test;
input store sales;
cards;
1 .
1 200
1 300
1 .
2 .
2 300
2 150
2 560
3 900
3 560
3 .
;
run;
data want;
set test;
if not missing(sales) then
output;
run;
data want2;
set want;
by store;
if first.store;
run;
Here is a one-step solution, for the sake of efficiency:
data want;
set test;
by store sales notsorted;
ct=ifn(first.store,0,ct);
ct+(first.sales and not missing(sales));
if ct=1;
drop ct;
run;
It's easy with a WHERE statement:
data want;
set have;
by store;
if first.store;
where sales > .;
run;
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.