Hi Community,
I would like to get help on staking data and then creating new variables. Here is an example.
Data have
PATID | visit | PA_TIM2M | PA_HAR2M | PA_TIM2R | PA_HAR2R |
10021 | 1 | 1 | 1 | 6 | 1 |
10031 | 1 | 0 | 3 | 2 | |
10041 | 1 | 1 | 2 | 1 | 1 |
Data want
PATID | visit | PA_HAR | times | intensity |
10021 | 1 | PA_HAR2M | 1 | 1 |
10021 | 1 | PA_HAR2R | 6 | 1 |
10031 | 1 | PA_HAR2M | 0 | |
10031 | 1 | PA_HAR2R | 3 | 2 |
10041 | 1 | PA_HAR2M | 1 | 2 |
10041 | 1 | PA_HAR2R | 1 | 1 |
The new variable,times, is from PA_TIM2M or PA_TIM2R and "intensity" is from PA_HAR2M or PA_HAR2R.
Thank you for the help
HI @CHL0320 See if this helps
data have;
input PATID visit PA_TIM2M PA_HAR2M PA_TIM2R PA_HAR2R;
cards;
10021 1 1 1 6 1
10031 1 0 . 3 2
10041 1 1 2 1 1
;
data want;
set have;
array t PA_TIM:;
array u PA_HAR:;
length PA_HAR $32;
do over u;
PA_HAR=vname(u);
Times=t;
Intensity=u;
output;
end;
drop PA_TIM2M PA_HAR2M PA_TIM2R PA_HAR2R;
run;
HI @CHL0320 See if this helps
data have;
input PATID visit PA_TIM2M PA_HAR2M PA_TIM2R PA_HAR2R;
cards;
10021 1 1 1 6 1
10031 1 0 . 3 2
10041 1 1 2 1 1
;
data want;
set have;
array t PA_TIM:;
array u PA_HAR:;
length PA_HAR $32;
do over u;
PA_HAR=vname(u);
Times=t;
Intensity=u;
output;
end;
drop PA_TIM2M PA_HAR2M PA_TIM2R PA_HAR2R;
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!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.