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;
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!
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.