cancel
Turn on suggestions
Showing results for
Search instead for
Did you mean:
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Obsidian | Level 7

Hello experts:

I have the original work year data, but they are presented as intervals, as described below.

data worktime;
input Firmid Personid Role$ Startyear Endyear ;
;
cards;
001 01 CEO 2016 2018
001 02 CFO 2018 2020
002 04 CEO 2016 2017
002 05 CFO 2022 2023
;
run;

I need panel data, broken down by year's work situation, as shown below.

data workdetail;
input Firmid Fyear Personid Role$ ;
;
cards;
001 2016 01 CEO
001 2017 01 CEO
001 2018 01 CEO
001 2018 02 CEO
001 2019 02 CFO
001 2020 02 CFO
002 2016 04 CEO
002 2017 04 CEO
002 2022 05 CFO
002 2023 05 CFO
;
run;

Thanks for your assistance🙏.

0 Likes
1 ACCEPTED SOLUTION

Accepted Solutions
Barite | Level 11

Hi @shawnchen0321 ,

you coul for example use a do-loop:

data worktime;
input Firmid Personid Role$ Startyear Endyear ;
;
cards;
001 01 CEO 2016 2018
001 02 CFO 2018 2020
002 04 CEO 2016 2017
002 05 CFO 2022 2023
;
run;
data workdetail;
	retain Firmid Fyear Personid Role;
	drop Startyear Endyear i;
	set worktime;
	format Firmid z3. Personid z2.;
	do i = Startyear to Endyear;
		Fyear = i;
		output;
	end;
run;

to get

MarkusWeick_0-1763212875366.png

Please help to keep the community friendly.
Like posts you agree with or like. Mark helpful answers as "accepted solutions". Generally have a look at https://communities.sas.com/t5/Getting-Started/tkb-p/community_articles
0 Likes
2 REPLIES 2
Barite | Level 11

Hi @shawnchen0321 ,

you coul for example use a do-loop:

data worktime;
input Firmid Personid Role$ Startyear Endyear ;
;
cards;
001 01 CEO 2016 2018
001 02 CFO 2018 2020
002 04 CEO 2016 2017
002 05 CFO 2022 2023
;
run;
data workdetail;
	retain Firmid Fyear Personid Role;
	drop Startyear Endyear i;
	set worktime;
	format Firmid z3. Personid z2.;
	do i = Startyear to Endyear;
		Fyear = i;
		output;
	end;
run;

to get

MarkusWeick_0-1763212875366.png

Please help to keep the community friendly.
Like posts you agree with or like. Mark helpful answers as "accepted solutions". Generally have a look at https://communities.sas.com/t5/Getting-Started/tkb-p/community_articles
0 Likes
Obsidian | Level 7

It works perfectly, thank you very much😊.

sasinnovate.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just 495ドル!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
[フレーム]

AltStyle によって変換されたページ (->オリジナル) /