BookmarkSubscribeRSS Feed
robertrao
Quartz | Level 8

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

4 REPLIES 4
Tom
Super User Tom
Super User

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 ;

robertrao
Quartz | Level 8

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

Tom
Super User Tom
Super User

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


UrvishShah
Fluorite | Level 6

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 783 views
  • 0 likes
  • 3 in conversation