BookmarkSubscribeRSS Feed
SASMuggleE
Calcite | Level 5

I have some data the looks like this

 

Subject     Start     End     Var1     V2

1                 1         4        xx         yy

1                 5         6        xx        zz

2                 1          3        yy        ww

...

 

I want it to look like this:

Subject     Time     Var1     V2

1                 1         xx         yy

1                 2         xx         yy

1                 3         xx         yy

1                 4         xx         yy

1                 5         xx        zz

1                 6         xx        zz

2                 1         yy        ww

2                 2         yy        ww

2                 3         yy        ww

...

 

What would my program array look like?

2 REPLIES 2
GeorgeBonanza
Obsidian | Level 7

I think this should work.

 

data HAVE;
	input SUBJECT $ START END VAR1 $ VAR2 $;
	datalines;
1 1 4 xx yy
1 5 6 xx zz
2 1 3 yy ww
;
run;

data WANT (drop= START END);
	retain SUBJECT TIME VAR1 VAR2;
	set HAVE;
	do TIME = START to END;
		output;
	end;
run;
Reeza
Super User

This wouldn't require an array. SAS data steps loop automatically so no need to control that. You need to output multiple records per line so create a loop and use an explicit OUTPUT statement to print that line out once for each time.

 

In SAS arrays are used for working with multiple variables with the data on a single row, though you can across rows it's a bit more complex. It is not used to represent columns however.

 

Here's a tutorial on using Arrays in SAS
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 531 views
  • 0 likes
  • 3 in conversation