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

Hello everyone! 

 

I have two variables and I want to add two new variables. One of the variables that exist is the employment status of the study participants (1=employed, 2= unemployed) and the other is the year that the participant answered the employment question. I want to make a third variable that indicates the number of years each person was employed. Similarly, I intend to add a fourth variable that cumulatively adds up the years of unemployment and illustrates it for each year. For example, Case ID 1003 was unemployed in 1984, then was employed in the years of 1985 to 1987 (3 years) and again was unemployed in 1988. Hence, in the year of 1988, she had been unemployed for two years and employed for three years. 

 

I was wondering if you could please help me with programming these new variables? I have also attached a sample data pdf file.

 

Thank you for your consideration.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data want;
set have;
by case_id;
if first.case_id then do;
Yearsbeingunemployed=0;
Yearsbeingemployed=0;
end;
if 	Employmentstatus=1 then  Yearsbeingemployed+1;
else if  Employmentstatus=2 then  Yearsbeingunemployed+1;
run;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

I can't and am not allowed to open attachments. Can you please paste your sample HAVE and sample WANT as text. Also, explain the logic in neat bullet points rather than long sentences. Just my 2 cents. Thank you

novinosrin
Tourmaline | Level 20
data want;
set have;
by case_id;
if first.case_id then do;
Yearsbeingunemployed=0;
Yearsbeingemployed=0;
end;
if 	Employmentstatus=1 then  Yearsbeingemployed+1;
else if  Employmentstatus=2 then  Yearsbeingunemployed+1;
run;
Sinakian1
Fluorite | Level 6

Thank you indeed. It worked exactly as I wanted. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep using the code window (its the {i} above the post area).  Also show what the output should look like.  

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
  • 4 replies
  • 857 views
  • 4 likes
  • 3 in conversation