Hello everyone,
I have a dataset with multiple columns but they are essentially two numeric variables (Score and Measure). I need to reformat the dataset into one that only contains these two variables. Thank you very much in advance!
data example;
input score1 measure1 score2 measure2 score3 measure3;
datalines;
0 5.678922 3 4.666666 6 3.555555
1 5.123456 4 4.234567 7 2.888888
2 4.999999 5 3.876543 8 1.555555
;
data want;
input score measure;
datalines;
0 5.678922
1 5.123456
2 4.999999
3 4.666666
4 4.234567
5 3.876543
6 3.555555
7 2.888888
8 1.555555
;
try this code.
data want;
set example;
length score measure 8;
array sc{3} score1-score3;
array ms{3} measure1-measure3;
do i=1 to dim(sc);
score=sc{i};
measure=ms{i};
output;
end;
drop i score1-score3 measure1-measure3;
run;
proc sort data=want;
by score;
run;
try this code.
data want;
set example;
length score measure 8;
array sc{3} score1-score3;
array ms{3} measure1-measure3;
do i=1 to dim(sc);
score=sc{i};
measure=ms{i};
output;
end;
drop i score1-score3 measure1-measure3;
run;
proc sort data=want;
by score;
run;
Thank you so much!
If you don't really have other information it might be that you could read the source file differently:
data example; input score measure @@; datalines; 0 5.678922 3 4.666666 6 3.555555 1 5.123456 4 4.234567 7 2.888888 2 4.999999 5 3.876543 8 1.555555 ;
The @@ used here means in effect "keep using the same input variables until you run out of data".
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.