BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
CHL0320
Obsidian | Level 7

Hi Community,

 

I would like to get help on staking data and then creating new variables. Here is an example.

 

Data have

 

PATIDvisitPA_TIM2MPA_HAR2MPA_TIM2RPA_HAR2R
1002111161
1003110 32
1004111211

 

Data want

 

PATIDvisitPA_HARtimesintensity
100211PA_HAR2M11
100211PA_HAR2R61
100311PA_HAR2M0 
100311PA_HAR2R32
100411PA_HAR2M12
100411PA_HAR2R11

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

1 REPLY 1
novinosrin
Tourmaline | Level 20

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 1 reply
  • 663 views
  • 0 likes
  • 2 in conversation