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.
No, SAS variables need to start with a letter or _.
You can assign the label though, using the IDLABEL statement.
Yeah, sorry, didn't catch that.
Use COMPRESS() within a second data step to remove the letters then and keep the numbers and - symbol.
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.