Adding extra years for each observation

Accepted Solution Solved
Reply
Contributor
Posts: 51
Accepted Solution

Adding extra years for each observation

Hi,

 

I want to add year 12/31/1971 and 12/31/1986 to each ID. Can anyone please help me to do it. I have attached an excel file with sample data. I will be grateful if anyone can help me.


Accepted Solutions
Solution
‎05-12-2017 01:06 AM
Grand Advisor
Posts: 17,332

Re: Adding extra years for each observation

[ Edited ]

Use BY groups again and LAST with explicit OUTPUT.

 

data want; 
set have;
by id;

output;

if last.id then do;
    date='01Jan2017'd; output;
    date='02Jan2017'd; output;
end;

run;


nazmul wrote:

Hi,

 

I want to add year 12/31/1971 and 12/31/1986 to each ID. Can anyone please help me to do it. I have attached an excel file with sample data. I will be grateful if anyone can help me.



 

View solution in original post


All Replies
Solution
‎05-12-2017 01:06 AM
Grand Advisor
Posts: 17,332

Re: Adding extra years for each observation

[ Edited ]

Use BY groups again and LAST with explicit OUTPUT.

 

data want; 
set have;
by id;

output;

if last.id then do;
    date='01Jan2017'd; output;
    date='02Jan2017'd; output;
end;

run;


nazmul wrote:

Hi,

 

I want to add year 12/31/1971 and 12/31/1986 to each ID. Can anyone please help me to do it. I have attached an excel file with sample data. I will be grateful if anyone can help me.



 

Contributor
Posts: 51

Re: Adding extra years for each observation

Thank you very much for your reply. Your code adds two additional years:
1976 and 2017 after each observation but it also copies the other variables
associated with last reported year of each observation in the missing year.
I want the two additional year and all the variables associated with the
year missing (.). Could you please modify your code to do it? I have added
an excel file with my original data and expected SAS output.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Contributor
Posts: 51

Re: Adding extra years for each observation

Thank you very much for your reply. Your code adds two additional years:
1976 and 2017 after each observation but it also copies the other variables
associated with last reported year of each observation in the missing year.
I want the two additional year and all the variables associated with the
year missing (.). Could you please modify your code to do it? I have added
an excel file with my original data and expected SAS output.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
Grand Advisor
Posts: 17,332

Re: Adding extra years for each observation

1. There's no attachment

2. Set the values to missing manually or use call missing() in the do condition. 

Contributor
Posts: 51

Re: Adding extra years for each observation

Thank you. I set other variable as missing with if function.

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 122 views
  • 0 likes
  • 2 in conversation