sas >> need help in IML programe

by Umrao » Mon, 01 Sep 2008 18:01:59 GMT

I have an IML programe as follows
proc iml;
a={1 2,
1 3,
2 3}
;
b=nrow(a);
c=ncol(a);
v=max(a);

cs=j(c,1,0);
do i =1 to c;
ss=0;
do j=1 to b;
if a[j,i] ^= . then ss = ss+1;
end;
cs[i,1]=ss;
end;
n=sum(cs);

d=j(n,v,0);
ss1=0;
do i = 1 to c;
do j = 1 to b;
if a[j,i] ^= . then
do;
ss1=ss1+1;
do k = 1 to v;
if a[j,i] = k then
d[ss1,k] =1;
end;
end;
end;
end;
print d;
run;

output for this is as follows
1 0 0
1 0 0
0 1 0
0 1 0
0 0 1
0 0 1

now if I replase the matrix a by
a={. 2,
. 3,
2 3}

ie we replace an element by a missing value then I get the output as
0 1 0
0 1 0
0 0 1
0 0 1
now my problem is that if I replace any element of the matrix then
the column number corresponding to that element should be deleted from
the output ie for this example I want the column number 1 to be
deleted in the ouput.
I whant the output as follows
1 0
1 0
0 1
0 1

(if we replace element 2 with a dot then in the output column 2
should be deleted)


sas >> need help in IML programe

by pallab.ghosh07 » Mon, 01 Sep 2008 23:06:22 GMT




> 1 gt;0 0
> 0>1 >
> 0 1 > 0
> 0 > gt;0 1
> 0 0 1
>
> ={. 2,
> . 3,
> 2 3}
>
> ie we replace an element by a miss>ng value then > get the outpu> as
> 0 gt;1 0
> 0>1 0
> 0 0 1
> 0 0 1
> ow my p>oblem is that if I replace any element of the matrix then
> the column n>mber corresponding to that element should be deleted from
> the o>tput ie for this example>I want the column number 1 to be> > dele>ed in t>e ouput>
> I w>an> the output as follows
> 1 0
> 1 0
> 0 1
> 0 1
>
> (i> we replace element 2 with a dot hen in the output column 2
> should be deleted)

Hi Umrao,
I tried to solve your probelm.The logic is very simple.First find out
the ith column sum,if it equals to zero delete the ith column.Please
note i can take any value as you mentioned.Here the codes:

proc iml;
a={. 2, . 3, 2 3} ;
b=nrow(a);
c=ncol(a);
v=max(a);

cs=j(c,1,0);
do i =1 to c;
ss=0;
do j=1 to b;
if a[j,i] ^= . then ss = ss+1;

end;
cs[i,1]=ss;
print cs;
end;
n=sum(cs);


d=j(n,v,0);
ss1=0;
do i = 1 to c;
do j = 1 to b;
if a[j,i] ^= . then
do;
ss1=ss1+1;
do k = 1 to v;
if a[j,i] = k then
d[ss1,k] =1;
end;
end;
end;
end;
print a b c cs v d;
col_sum = j(1,v,0);

do i = 1 to v;
col_i = d[,i];
col_sum_i = col_i[+,];
if col_sum_i = 0 then do;

if i = 1 then do;
d_star = d[,(i+1):v];
end;

if i = v then do;
d_star = d[,1:(v-1)];
end;

if i ^= 1 then do;
d_star1 = d[,1:(i-1)];
d_star2 = d[,(i+1):v];
d_star = d_star1||d_star2;
end;
end;
print d_star;
end;

quit;



Similar Threads

1. Need help with basic IML, "RTFM"

2. I need help with proc IML

Dear listers,

I am an (old) new SAS user and I have some difficulties using the proc IML.

I am trying to figure out how to use the USE and READ statements in proc IML
with several datasets that are output from the TABULATE procedure.
The datasets names are (test1-test5). I would like to use them in loops with
proc IML.

I have first tried to write USE concat('Test',char(i,1)) /*i referencing the
dataset number*/
That didn't work.

I then tried to assign the dataset name to a value.

curr_data=concat('Test',char(i,1));
USE curr_data;

That doesn't work either.



2. The second point I don't understand is why the READ statement or others
don't either work with loops.

do j= minV to max(VAR[i]);
I was forced to assign minV a value (minV=min(VAR[i]) rather than just
writing
do j=max(VAR[i]) to max(VAR[i])

- I have the same problem with the READ statement. IML doesn't recognize :
read all var{ concat('PctN_',pctSuffix[i])} into ar where (VAR[i]=j);
- I needed to write :
break_var=concat('PctN_',pctSuffix[i]);
an_var=VAR[i];
read all var{ break_var } into ar where (an_var=j);


Any help would be greatly appreciated


Below my proc :


proc iml;
show
datasets;
show
contents;
reset
print;
pctSuffix={
"100" "010" "110"};
print
pctSuffix;
countryVal={
. 2 4};
print
countryVal;
specVal={
. 1 2 3};
print
specVal;
AN_TYPE={
FREQ
FREQ
FREQ
FREQ
FREQ
};
print
AN_TYPE;
VAR={
Q01_1a
Q01_2a
Q01_3a
Q01_4a
Q01_5a
};
print
VAR;

start
myproc;
do
i=2 to NCOL(AN_TYPE);
print i;
if AN_TYPE[i]=FREQ then do;
minV=min(VAR[i]);
do j= minV to max(var[i]);
mydata=concat(
'Test',char(i,1));
use mydata;
break_var=concat(
'PctN_',pctSuffix[i]);
an_var=VAR[i];
read all var{ break_var } into ar where (an_var=j);
print ar;
end;
end;
end
;
finish
myproc;
run
myproc;
quit
;

3. Need help with help need

4. SAS/IML LAV Routine Needed

Hi:

I am tech support at KSU.  I have a faculty member here that needs to run a
regression with a general form of Y=a+year dummy
variables+b1X1+b2X2+b3X3...  He is looking for a SAS/IML LAV routine to run
a Least Absolute Deviations (LAD) regression.  Does anyone have a routine
that may work for him or a suggestion as to what other SAS routines(or
procs) may be appropriate?

Thanks!

Tina

5. Earn $ 50 Per Hour With CJ's Affiliate Programe

6. without changing code how to get updated sas programes

Hi sir,
Pls help  me for this coding modification.

%window tdmu irow=4 rows=22
icolumn=10 columns=60
#5 @08 "tdmu reports" attr=highlight color=blue @25 "sysday
&sysdate9"color=blue
#7 @08 "select to execute:" attr=highlight color=blue
#9 @08 "1 td space report"
#10 @08 "2 wd report"
#11 @08 "3 compliance report"
#12 @08 "4 compliance report for pi"
#13 @08 "5 wd email program"
#14 @08 "6 compliance report email program"
#15 @08 "Q quit"
#18 @27 getreport 1 attr=underline
#22 @27 "please ppress enter to continue." attr=underline
attr=highlight color=blue;
%let loction=D:\Documents and Settings\Desktop\SAS_Programs
%Macro test;

%if &getreport=1 % then %do

%include ,&location\test1';

end;

%else %if &getreport=2 %then %do

%include '&location\test2';

end;

%else %if &getreport=3 %then %do

%include '&location\test3';  (here i don't want to change the
file


                 name(test3.sas),it should take latest such
as


            test3_v2.sas...)

end;
%else %if %upcase (&getreport)='Q' %then %do;
stop;
%end;
%else %then %do;%let sysmsg=
%upcase(&sysmsg) is not valid,
enter option online above;
%display TDMU;
%end;
%let getreport=;
%mend TDMU_report;
%TDMU_report;
%TDMU_report
run;



%mend;
Regards
venkat prasad

7. FW: A MACRO HELP NEEDED - I am new in Macro (please help me)

8. A MACRO HELP NEEDED - I am new in Macro (please help me)

I have a sample code as below:


%Macro select (AgB, CAB);


if &AgB = '1' then AgB = "Aucun sympt^ome";
     else if &AgB = "2" then AgB = "Atteinea";
  else if &AgB = "3" then AgB = "Atteineb";
     else if &AgB = "4" then AgB = "Atteinec";
     else if &AgB = "p" then AgB = "Atteined";
     else if &AgB = "q" then AgB = "Atteinee";
    else if &AgB = "z" then AgB = "Atteinef";
if &CAB = '1' then CAB = "Aucun sympt^ome";
     else if &CAB = "2" then CAB = "Atteinea";
  else if &CAB = "3" then CAB = "Atteineb";
     else if &CAB = "4" then CAB = "Atteinec";
     else if &CAB = "p" then CAB = "Atteined";
     else if &CAB = "q" then CAB = "Atteinee";
    else if &CAB = "z" then CAB = "Atteinef";
  run;

%Mend select;
%select (Choutri, Passenger)
run;






Now there is a repitation of the same group of statements or group of
codes twice ( actually
in the original program there is hundreds time repitaion). How can I put
those
repeted statements or codes in a Macro? The program already has a Macro
select.