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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

5 REPLIES 5
Reeza
Super User

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.



 

nazmul
Quartz | Level 8
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. -##
nazmul
Quartz | Level 8
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. -##
Reeza
Super User

1. There's no attachment

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

nazmul
Quartz | Level 8

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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