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;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.