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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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