Desktop productivity for business analysts and programmers

Replacing a Date for a New Date

Accepted Solution Solved
Reply
Contributor
Posts: 42
Accepted Solution

Replacing a Date for a New Date

Hello,

 

I have records that are populated for each month of the calendar year that have a column for points. Points change per month. There is also one record per month. For example, John Smith has one record for Jan, one record for Feb, etc.  I pull this report every month so the reporting month changes.

 

I want to freeze his points on a specific month without impacting the other people in the dataset. So if I want to freeze his results as of June then I would not want to see July, Aug, Spet, or October on the report.  As of right now I used an excel doc to import names of people I wanted to do this for and have excluded months that I don't want (these months are indicated on the excel sheet). I.e. in the excel sheet i have John Smith and July 1, 2017.  So I excluded based on the date but I'm unsure of how to REPLACE the JUNE month with September so that September comes through with populated data of July. I tried to use a prompt but am unsure of how to go about doing this.

 

Hope this makes sense!


Accepted Solutions
Solution
‎10-03-2017 09:00 AM
Super User
Posts: 8,054

Re: Replacing a Date for a New Date

Posted in reply to mmagnuson

Suppose dataset have has id, date, and points. Dataset updates has id and date.

Sort both datasets by id and date, then run

data want;
merge
  have (in=a)
  updates (in=b)
;
by id date;
retain save_points;
if a;
if first.id then save_points = .;
if b then save_points = points;
if save_points ne . then points = save_points;
drop save_points;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎10-03-2017 09:00 AM
Super User
Posts: 8,054

Re: Replacing a Date for a New Date

Posted in reply to mmagnuson

Suppose dataset have has id, date, and points. Dataset updates has id and date.

Sort both datasets by id and date, then run

data want;
merge
  have (in=a)
  updates (in=b)
;
by id date;
retain save_points;
if a;
if first.id then save_points = .;
if b then save_points = points;
if save_points ne . then points = save_points;
drop save_points;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 133 views
  • 0 likes
  • 2 in conversation