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
Onyx | Level 15

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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