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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.