BookmarkSubscribeRSS Feed
corkee
Calcite | Level 5

Hi, I reshaped my dataset from long to wide and now need to change it back to long. The code I used to convert from long to wide is:

 

proc sort data=medicaid_new;
	by ParticipantID;
run;

proc transpose data=medicaid_new out=medicaid_wide1 prefix=HEDIS;
	by ParticipantID;
	id Time;
	var HEDIS;
run;

The time variable has values ranging from -15 to 15. Is it possible to reshape it from wide to long and to create a new "Time" variable with its original values? In wide format, the HEDIS variables are called: HEDIS_15 for Time = -15, HEDIS_14 for Time = -14, ... HEDIS15 for Time = 15. Any help would be greatly appreciated.

4 REPLIES 4
Reeza
Super User

No, SAS variables need to start with a letter or _. 

 

You can assign the label though, using the IDLABEL statement.

corkee
Calcite | Level 5
Hi Reeza, maybe my post isn't clear. Essentially, I want the dataset to look like this:
ID HEDIS Time
1 40 -15
1 35 -14
1 35 -13
...
1 36 14
1 37 15

Where the Time variable is based on the HEDIS_15 and etc. variables in the wide dataset (HEDIS_15 is Time -15 and HEDIS15 is Time 15).
Reeza
Super User

Yeah, sorry, didn't catch that.

 

Use COMPRESS() within a second data step to remove the letters then and keep the numbers and - symbol.

 

 

PGStats
Opal | Level 21

Simpler to use a data step in ths case:

 

data medicaid_long;
set medicaid_wide;
array h hedis_15 -- hedis15;
do time = -15 to 15;
	HEDIS = h{time};
	output;
	end;
keep participantID time HEDIS;
run;
PG

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 1249 views
  • 2 likes
  • 3 in conversation