Solved
Contributor
Posts: 50

# 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: 9,923

## Re: Replacing a Date for a New Date

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)
;
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
How to convert datasets to data steps
How to post code

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

## Re: Replacing a Date for a New Date

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)
;
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
How to convert datasets to data steps
How to post code
☑ This topic is solved.