BookmarkSubscribeRSS Feed
pawandh
Fluorite | Level 6

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?

3 REPLIES 3
SAS_inquisitive
Lapis Lazuli | Level 10
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;
Haikuo
Onyx | Level 15

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;

Astounding
PROC Star

It's easy with a WHERE statement:

 

data want;

set have;

by store;

if first.store;

where sales > .;

run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 1348 views
  • 1 like
  • 4 in conversation