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

Hi,

 

I want to expand data from this:

ID startdate enddate num
1 2/10/2010 2/16/2010 [0,1,0,2,4,7,0]
2 3/11/2010 3/17/2010 [0,1,3,0,1,2,0]

 

to this:

ID date num
1 2/10/2010 0
1 2/11/2010 1
1 2/12/2010 0
1 2/13/2010 2
1 2/14/2010 4
1 2/15/2010 7
1 2/16/2010 0
2 3/11/2010 0
2 3/12/2010 1
2 3/13/2010 3
2 3/14/2010 0
2 3/15/2010 1
2 3/16/2010 2
2 3/17/2010 0

 

 

I tried to look up proc expand but it seems not working in this example.  That would be great if someone can give me some suggestions. Thanks.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data want;
set have;

i=1;
do date=startdate to enddate;
num_single = scan(num,  i,  "[,]");
output;
i+1;
end;

run;

A basic data step is the best method here.

 


@daradanye wrote:

Hi,

 

I want to expand data from this:

ID startdate enddate num
1 2/10/2010 2/16/2010 [0,1,0,2,4,7,0]
2 3/11/2010 3/17/2010 [0,1,3,0,1,2,0]

 

to this:

ID date num
1 2/10/2010 0
1 2/11/2010 1
1 2/12/2010 0
1 2/13/2010 2
1 2/14/2010 4
1 2/15/2010 7
1 2/16/2010 0
2 3/11/2010 0
2 3/12/2010 1
2 3/13/2010 3
2 3/14/2010 0
2 3/15/2010 1
2 3/16/2010 2
2 3/17/2010 0

 

 

I tried to look up proc expand but it seems not working in this example.  That would be great if someone can give me some suggestions. Thanks.

 

 


 

View solution in original post

2 REPLIES 2
yabwon
Amethyst | Level 16

Do-loop plus scan function:

data have;
input ID	startdate mmddyy10.	enddate mmddyy10.	num $ 20.;
format startdate enddate mmddyy10.;
cards;
1	2/10/2010	2/16/2010	[0,1,0,2,4,7,0]
2	3/11/2010	3/17/2010	[0,1,3,0,1,2,0]
;
run;
proc print;
run;

data want;
  set have;
  format date mmddyy10.;
  i = 0;
  do date = startdate to enddate;
    i = i+1;
    N=input(scan(num, i, "[,]"),best.);
    output;
  end;
  drop startdate enddate num i;
  rename N=num;
run;
proc print;
run;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Reeza
Super User
data want;
set have;

i=1;
do date=startdate to enddate;
num_single = scan(num,  i,  "[,]");
output;
i+1;
end;

run;

A basic data step is the best method here.

 


@daradanye wrote:

Hi,

 

I want to expand data from this:

ID startdate enddate num
1 2/10/2010 2/16/2010 [0,1,0,2,4,7,0]
2 3/11/2010 3/17/2010 [0,1,3,0,1,2,0]

 

to this:

ID date num
1 2/10/2010 0
1 2/11/2010 1
1 2/12/2010 0
1 2/13/2010 2
1 2/14/2010 4
1 2/15/2010 7
1 2/16/2010 0
2 3/11/2010 0
2 3/12/2010 1
2 3/13/2010 3
2 3/14/2010 0
2 3/15/2010 1
2 3/16/2010 2
2 3/17/2010 0

 

 

I tried to look up proc expand but it seems not working in this example.  That would be great if someone can give me some suggestions. Thanks.

 

 


 

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 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
  • 2 replies
  • 954 views
  • 1 like
  • 3 in conversation