BookmarkSubscribeRSS Feed
Smitha9
Fluorite | Level 6

Hi,

I have a dataset A

ID      date

1      12/13/2022

1            .       

1      12/13/2022

1             .

2       03/26/1978

2             .

2             .

3        07/29/1980

4        10/02/1982

4                 .

 

I want the dataset B to fill the Date based on the ID's

Example:

 

ID      date

1      12/13/2022

1      12/13/2022       

1      12/13/2022

1      12/13/2022

2       03/26/1978

2       03/26/1978

2       03/26/1978      

3       07/29/1980

4       10/02/1982

4       10/02/1982        

 

data b; set a;

 

could you let me know how to do this in SAS?

 

thanks in advance

2 REPLIES 2
Tom
Super User Tom
Super User

If you only want to carry forward the dates (not try to move them backwards in the file) then try to UPDATE statement.

data want;
  update have(obs=0) have ;
  by id; 
  output;
run;
mkeintz
PROC Star

If there is no variation of DATE within each id, then:

 

data have;
  input ID      date :mmddyy10.;
  format date date9.;
datalines;
1      12/13/2022
1            .       
1      12/13/2022
1             .
2       03/26/1978
2             .
2             .
3        07/29/1980
4        10/02/1982
4                 .
run;

data want;
  merge have (keep=id date where=(date^=.)) have (drop=date)  ;
  by id;
run;

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 586 views
  • 0 likes
  • 3 in conversation