Hi ,
Below I have a list of variables used in the array step
in array one ib is always followed by et
in array two jtb is always followed by jxt
When there are numerous variables like this how can we represent the in shortcut
something like we do
ib: et: ??????
data want;
set have;
by mrn1;
array one {10} ib1 et1 ib2 et2 ib3 et3 ib4 et4 ib5 et5;
array two {10} jtb1 jxt1 jtb2 jxt2 jtb3 jxt3 jtb4 jxt4 jtb5 jxt5;
do i = 1 to dim(one);
end;
run;
Thanks
Not sure what you want. Why would it matter that the order is alternating IB and ET variables?
Why not just do
array one ib1-ib5 et1-et5 ;
or
array one ib: et: ;
If you need to treat the IB variables differently than the ET variables then use two different arrays for the two different groups of variables.
array ib ib1-ib5 ;
array et et1-et5;
or
array ib (5);
array et (5);
or
array ib ib: ;
array et et: ;
Or use a two dimensional array
array one (5,2) ib1-ib5 et1-et5 ;
Hi ,
Thnks for the reply.
I am trying to do a transpose using the arrays and ib and et is a pair.
After transpose i will have something like this
data want;
set have;
by mrn1;
array one {10} ib1 et1 ib2 et2 ib3 et3 ib4 et4 ib5 et5;
array two {10} jtb1 jxt1 jtb2 jxt2 jtb3 jxt3 jtb4 jxt4 jtb5 jxt5;
do i = 1 to dim(one);
category=vname(one{i});
value=(one{i});
unit=(two{i});
end;
run;
category value unit
ib1
et1
ib2
et2
ib3
et3
ib4
et4
ib5
et5;
Thanks
array one (5,2) ib1-ib5 et1-et5 ;
array two (5,2) jtb1-jtb5 jtx1-jtx5 ;
do pair=1 to 5;
do item=1 to 2;
category=vname(one(pair,item));
value = one(pair,item);
unit = two(pair,item);
output;
end;
end;
pair item category value unit
1 1 ib1
1 2 et1
2 1 ib2
2 2 et2
3 1 ib3
3 2 et3
4 1 ib4
4 2 et4
5 1 ib5
5 2 et5
Hi,
Try the following code...
proc contents data = have noprint varnum
out = list(keep = name varnum);
run;
proc sort data = list;
by varnum;
run;
proc sql noprint;
select name into :grp1 separated by " "
from list
where varnum LE 10;
select name into :grp2 separated by " "
from list
where varnum GT 10;
quit;
data want(keep = category value unit);
array one (*) &grp1.;
array two (*) &grp2.;
set have;
do i = 1 to dim(two);
category = vname(one(i));
value = one(i);
unit = two(i);
output;
end;
run;
-Urvish
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.