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-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!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

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