BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
y3arire_7
Fluorite | Level 6

Hi Is anyone here could share how to write the code to reflect the "Desired Results" as below?

 

I would like to have the blank field from "Membership_Type" to be replaced by number from the next following month with available data.

 

Truly appreciate if anyone could shed the light on this question.

Thank you so much!

 

YYYYMMCustomerMembership_TypeDesired Results
201712111001100
201801111001100
201802111001100
201803111001100
2018041.2200
2018051.2200
2018061.2200
2018071.2200
2018081.2200
2018091.2200
2018101.2200
201811122002200
201812122002200
201901122002200
2017123.3000
2018013.3000
2018023.3000
2018033.3000
2018043.3000
2018053.3000
201806330003000
201807330003000
201808330003000
201809330003000
201810330003000
201811330003000
201812330003000
1 ACCEPTED SOLUTION

Accepted Solutions
FredrikE
Rhodochrosite | Level 12

HI!

Something like (untested):

 

proc sort data = have out=tmp;

 by customer descending yyyymm;

run;

 

data want;

 set tmp;

 by customer descending yyyymm;

 retain desired_result;

 

 if not missing(membership_type) then desired_restult = membership_type;

run;

 

//Fredrik

View solution in original post

3 REPLIES 3
FredrikE
Rhodochrosite | Level 12

HI!

Something like (untested):

 

proc sort data = have out=tmp;

 by customer descending yyyymm;

run;

 

data want;

 set tmp;

 by customer descending yyyymm;

 retain desired_result;

 

 if not missing(membership_type) then desired_restult = membership_type;

run;

 

//Fredrik

TomKari
Onyx | Level 15

Here's a very similar version, but it will keep the result dataset in the original sequence, whether or not there's a sortable key.

 

Tom

 

data Inter01;
	set Have;
	_SN = _n_;
run;

proc sort data=Inter01;
	by descending _SN;
run;

data Inter02;
	retain old_membership_type;
	set Inter01;

	if _n_ = 1 then
		old_membership_type = membership_type;

	if missing(membership_type) then
		membership_type = old_membership_type;
	old_membership_type = membership_type;
	drop old_membership_type;
run;

proc sort data=Inter02 out=Want(drop=_SN);
	by _SN;
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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 765 views
  • 0 likes
  • 3 in conversation