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

I am sure that I can avoid the Do loop in this code. It works but I want to "translate" the numerical matrix to a categorical one.

Is there a way to map the numerical matrix RES_T  to its char sibling RES_T_CH by using the DESC matrix?

 

PROC IML;

X=1 : 8;
Y=1:10;

RES=T(Y)*X;

LABLX=CHAR(X);
LABLY=CHAR(Y);

R=PALETTE("BLUES",4);

RES2=(MOD(RES,2)=0);
RES4=(MOD(RES,4)=0);
RES8=(MOD(RES,8)=0);

RES_T=RES2+RES4+RES8;

DESC={"no divideix ni per 2, ni 4, ni 8" "divideix per 2" "divideix per 4" "divideix per 8"};
/*print desc;*/

RES_T_CH=J(10,8, "                               ");


DO I=1 TO NROW(RES)*NCOL(RES);
RES_T_CH[I]=DESC[RES_T[I]+1];
END;

CALL HEATMAPDISC(RES_T_ch, R) TITLE="tasca multiplicar per 2,4 i 8" DISPLAYOUTLINES=1 SHOWLEGEND=1;
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Yes. No need loop, just directly refer to RES_T as an index matrix.

 

ods html;


PROC IML;

X=1 : 8;
Y=1:10;

RES=T(Y)*X;

LABLX=CHAR(X);
LABLY=CHAR(Y);

*R=PALETTE("BLUES",4);

RES2=(MOD(RES,2)=0);
RES4=(MOD(RES,4)=0);
RES8=(MOD(RES,8)=0);

RES_T=RES2+RES4+RES8;

DESC={"no divideix ni per 2, ni 4, ni 8" "divideix per 2" "divideix per 4" "divideix per 8"};
/*print desc;*/


RES_T_CH=SHAPE(DESC[RES_T+1],NROW(RES_T));

print res_t,res_t_ch;
quit;

View solution in original post

1 REPLY 1
Ksharp
Super User

Yes. No need loop, just directly refer to RES_T as an index matrix.

 

ods html;


PROC IML;

X=1 : 8;
Y=1:10;

RES=T(Y)*X;

LABLX=CHAR(X);
LABLY=CHAR(Y);

*R=PALETTE("BLUES",4);

RES2=(MOD(RES,2)=0);
RES4=(MOD(RES,4)=0);
RES8=(MOD(RES,8)=0);

RES_T=RES2+RES4+RES8;

DESC={"no divideix ni per 2, ni 4, ni 8" "divideix per 2" "divideix per 4" "divideix per 8"};
/*print desc;*/


RES_T_CH=SHAPE(DESC[RES_T+1],NROW(RES_T));

print res_t,res_t_ch;
quit;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 1 reply
  • 579 views
  • 0 likes
  • 2 in conversation