I have a dataset with the following columns:
Subject Date1 SBP1 DBP1 Date2 SBP2 DBP2 Date3 SBP3 DBP3 ..... Date30 SBP30 DBP30
=============== =============== =============== ..... ==================
and I would like to normalise into the following:
Subje Date SBP DBP
---- ---- --- ---
Subj1 Date1 SBP1 DBP1
Subj1 Date2 SBP2 DBP2
Subj1 Date3 SBP3 DBP3
.....
Subj1 Date30 SBP30 DBP30
Subj2 Date1 SBP1 DBP1
Subj2 Date2 SBP2 DBP2
Subj2 Date3 SBP3 DBP3
.....
Subj2 Date30 SBP30 DBP30
I can think of one solution where I Union the dataset 30 times so:
select subject, Date1, SBP1, DBP1 from ds
union
select subject, Date2, SBP2, DBP2 from ds
union
....
select subject, Date30, SBP30, DBP30 from ds
But hopefully there is a better way?
Yep, DATA step and arrays or PROC TRANSPOSE.
data want;
drop i date1 - date30 sbp1 - sbp30 dbp1 - dbp30;
set have;
array dates (*) date1 - date30;
array sbps (*) sbp1 - sbp30;
array dbps (*) dbp1 - dbp30;
do i = 1 to dim(dates);
date = dates(i);
sbp = sbps(i);
dbp = dbps(i);
output;
end;
run;
Yep, DATA step and arrays or PROC TRANSPOSE.
data want;
drop i date1 - date30 sbp1 - sbp30 dbp1 - dbp30;
set have;
array dates (*) date1 - date30;
array sbps (*) sbp1 - sbp30;
array dbps (*) dbp1 - dbp30;
do i = 1 to dim(dates);
date = dates(i);
sbp = sbps(i);
dbp = dbps(i);
output;
end;
run;
Thanks SASKiwi.
Is it possible to use a proc transpose directly in SAS VA? (I haven't tried this level of SAS coding in VA yet.)
Also, can arrays be used to build line charts in VA?
The easiest way to fix this issue is to transform the data before loading into VA LASR. You can run the code I've provided in SAS Studio which is available in SAS VA. PROC TRANSPOSE also requires SAS code so I suggest you stick with the code in my example.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.
Find more tutorials on the SAS Users YouTube channel.