I have a dataset that has data as follows:
Name Zip Measure_ID Score
Hospital A 12345 Rate1 0.2
Hospital A 12345 Rate2 .
Hospital A 12345 Rate3 .
Hospital B 54321 Rate1 1.5
Hospital B 54321 Rate2 0.4
Hospital B 54321 Rate3 .
Hospital C 24680 Rate1 .
Hospital C 24680 Rate2 .
Hospital C 24680 Rate3 .
I would like to have it by hospital:
Name Zip Rate1 Rate2 Rate3
Hospital A 12345 0.2 . .
Hospital B 54321 1.5 0.4 .
Hospital C 24680 . . .
I sorted the dataset by hospital and started by converting measure_id to columns through an array:
array measure (3) rate1 rate2 rate3;
But, I can't figure out how to handle the score column since I don't want to give it its own columns, I essentially want to make it the values while measure_id becomes column names.
May be easier than you think:
proc transpose data=have out=want (drop=_name_)
;
by name;
copy zip;
id measure_id;
run;
Drop=_name_ excludes the column that would have the original variable Score.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.