BookmarkSubscribeRSS Feed
kushi_wije
Calcite | Level 5
Hello, I am pretty new to SAS and was wondering if someone
could help me with the following:

I have sample data set as follows:

name start_week end_week
----- ---------- --------
andy 3 8
cindy 4 6
jess 1 5

and I want to create a data as follows from the above data set.

name week
---- ----
andy 3
andy 4
andy 5
andy 6
andy 7
andy 8
cindy 4
cindy 5
cindy 6
jess 1
jess 2
jess 3
jess 4
jess 5

Any ideas are greatly appreciated!

Thanks very much!
Kushi_Wije
3 REPLIES 3
kkid
SAS Employee
data work.start;
infile cards;
input name $1-8 start_week end_week ;
cards;
andy 3 8
cindy 4 6
jess 1 5
;
run;

data work.finish(rename=(start_week=week));
set work.start;
do while(start_week<=end_week);
output;
start_week+1;
end;
drop end_week;
run;
deleted_user
Not applicable
Or you could do this, which is easier to read (probably):

data work.finish(drop=start_week end_week);
set work.start;

do week=start_week to end_week;
output;
end;
run;
JohnH
Fluorite | Level 6
you essentially want to transpose your data from horizontal to vertical. You can use Proc Transpose and ask it to transpose start & end week by name.

sas-innovate-2026-white.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 save with the early bird rate—just $795!

Register now

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 3 replies
  • 1637 views
  • 0 likes
  • 4 in conversation