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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.